Trying to delete folders by date, I have 3 folders, today, yesterday,
daybefore.
I want to keep today and yesterday
this command echos only the daybefore folder, which is want I want
FORFILES -pD:/TEST -s -M*.* -D-2 -c"CMD /C ECHO @PATH"
this command i get a message "The process cannot access the file because
it is being used by another process",but it removes today. yesterday and the
daybefore folders.
FORFILES -pD:/TEST -s -M*.* -D-2 -c"CMD /C RD /S /Q @PATH".
What am I doing wrong?
Thanks, Tom
>Trying to delete folders by date, I have 3 folders, today, yesterday,
>daybefore.
>I want to keep today and yesterday
Try this Tom, it will delete all folders but keep the newest two.
@echo off
for /f "skip=2 delims=" %%a in ('dir /ad /b /on') do echo rd /s /q "%%a"
It does it by date, and skips to the newest ones.
Have a look at the output from the command
dir /?
The /on switch used by foxidrive will sort the output by name, hence
the command will skip the directories whose names start with the low
letters of the alphabet. You can set your own order - best to test it
on a sample folder!
>> Does this work because it skips the 1st 2 directories? My directory names
>> are not today. etc. I just use these names for examples
>> Thanks, Tom
>
>Have a look at the output from the command
>
>dir /?
>
>The /on switch used by foxidrive will sort the output by name, hence
>the command will skip the directories whose names start with the low
>letters of the alphabet. You can set your own order - best to test it
>on a sample folder!
Oops. It was meant to be by reverse date. o-d
I tested it and pasted the wrong line - mea culpa.
@echo off
for /f "skip=2 delims=" %%a in ('dir /ad /b /o-d') do echo rd /s /q "%%a"
Did you really use D:/Test instead of D:\Test?
>
>"Tom" <th...@aol.net> wrote in message
>news:qzCel.26359$1L3....@newsfe20.iad...
>> winxp sp3
>>
>> Trying to delete folders by date, I have 3 folders, today, yesterday,
>> daybefore.
>> I want to keep today and yesterday
>>
>> this command echos only the daybefore folder, which is want I want
>> FORFILES -pD:/TEST -s -M*.* -D-2 -c"CMD /C ECHO @PATH"
>>
>> this command i get a message "The process cannot access the file because
>> it is being used by another process",but it removes today. yesterday and
>> the daybefore folders.
>> FORFILES -pD:/TEST -s -M*.* -D-2 -c"CMD /C RD /S /Q @PATH".
>>
>Does anyone know why this :forfiles"code won't work?
forfiles doesn't operate on folders AFAICS.
>I did get the "for /f" to work the way I wanted
Was that did, or did not?