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
delete files in Folder with version-stamp
Moderator: DosItHelp
Re: delete files in Folder with version-stamp
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:
If the displayed files are the right ones for deletion, remove the ECHO part before the DEL command.
Antonio
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"
)
)
Antonio
Re: delete files in Folder with version-stamp
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
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
Re: delete files in Folder with version-stamp
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.
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.
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: delete files in Folder with version-stamp
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
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