delete files in Folder with version-stamp

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Chris1985
Posts: 2
Joined: 27 Jan 2019 10:42

delete files in Folder with version-stamp

#1 Post by Chris1985 » 27 Jan 2019 10:53

Hi

I need a batch file for delete of many files with a version-stamp. I have found a Code for the newest file in a folder, but i dont now rebuild it.

@echo off & setlocal
set "MySearchString=_"
for /r %%a in (*) do for /f "delims=" %%i in ('echo("%%~na" ^| findstr /i "%MySearchString%"') do del "%%~fa"


this are my files in my folder for example
6578_01.pdf
6578_02.pdf
6578_03.pdf
8844_12.pdf
8844_13.pdf
8844_14.pdf
0815_12.pdf
0815_20.pdf

and this i need as result:
6578_03.pdf
8844_14.pdf
0815_20.pdf

I hope someone can help me

thanks
Chris

Aacini
Expert
Posts: 1615
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: delete files in Folder with version-stamp

#2 Post by Aacini » 27 Jan 2019 12:43

I am afraid I don't understand your requirement... Do you want to remove all files with the same string before the underscore, excepting the last one? If so, then you may try this solution:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "group="
for /F "tokens=1* delims=_" %%a in ('dir /A-D /B *.pdf') do (
   if "%%a" neq "!group!" (
      set "group=%%a"
      set "file=%%b"
   ) else (
      ECHO del "!group!_!file!"
      set "file=%%b"
   )
)
If the displayed files are the right ones for deletion, remove the ECHO part before the DEL command.

Antonio

Chris1985
Posts: 2
Joined: 27 Jan 2019 10:42

Re: delete files in Folder with version-stamp

#3 Post by Chris1985 » 28 Jan 2019 01:40

Hi

thanks
it works with the correct "date created", but i must copy all files to another location an there changed the created time.
Would it be possible than the batch can the "date modified" time used? This time are not changed on copy......


Thanks for help
Chris

amzoun95
Posts: 1
Joined: 06 Feb 2019 10:33

Re: delete files in Folder with version-stamp

#4 Post by amzoun95 » 06 Feb 2019 10:35

The reason you can't delete those and they are read-only is because most
files there are in the "read only memory" of the device (the ROM). Which
files do you want to delete from the Windows directory?

Some things, like the Start Menu folder, and be modified by you are an
application but the system files that are needed by the OS are secure.

pieh-ejdsch
Posts: 204
Joined: 04 Mar 2014 11:14
Location: germany

Re: delete files in Folder with version-stamp

#5 Post by pieh-ejdsch » 13 Feb 2019 13:35

Hello Chris1985,

and why exactly do you want to change this creation time?
Either you make a wrong file versioning, which always creates an even younger date of creation of a file, because this is newly created.
Or they can properly version by backing up changed files leaving the original creation date.
At the moment, it looks like they have no strategy for backing up the data.
What are you planning to do?

Phil

Post Reply