Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Forfiles RD /S /Q

288 views
Skip to first unread message

Tom

unread,
Jan 24, 2009, 6:02:47 AM1/24/09
to
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".
What am I doing wrong?
Thanks, Tom


foxidrive

unread,
Jan 24, 2009, 8:05:08 AM1/24/09
to
On Sat, 24 Jan 2009 06:02:47 -0500, "Tom" <th...@aol.net> wrote:

>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"

Tom

unread,
Jan 24, 2009, 12:54:28 PM1/24/09
to

"foxidrive" <got...@woohoo.invalid> wrote in message
news:l94mn4hla53ifu1ri...@4ax.com...
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


foxidrive

unread,
Jan 24, 2009, 12:57:08 PM1/24/09
to

It does it by date, and skips to the newest ones.


Pegas...@yahoo.com

unread,
Jan 24, 2009, 12:58:34 PM1/24/09
to
On 24 Jan, 18:54, "Tom" <t...@aol.net> wrote:
> "foxidrive" <got...@woohoo.invalid> wrote in message
>
> news:l94mn4hla53ifu1ri...@4ax.com...> On Sat, 24 Jan 2009 06:02:47 -0500, "Tom" <t...@aol.net> wrote:
>
> >>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"
>
> 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!

foxidrive

unread,
Jan 24, 2009, 1:26:44 PM1/24/09
to
On Sat, 24 Jan 2009 09:58:34 -0800 (PST), Pegas...@yahoo.com wrote:

>> 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"

Tom

unread,
Jan 24, 2009, 1:32:41 PM1/24/09
to

"foxidrive" <got...@woohoo.invalid> wrote in message
news:26nmn45o9hofgm45j...@4ax.com...
Thanks, I will try it
Tom


Tom

unread,
Jan 25, 2009, 8:07:36 AM1/25/09
to

"Tom" <th...@aol.net> wrote in message
news:qzCel.26359$1L3....@newsfe20.iad...
Does anyone know why this :forfiles"code won't work?
I did get the "for /f" to work the way I wanted


ten.n...@virgin.net

unread,
Jan 25, 2009, 10:40:15 AM1/25/09
to

Did you really use D:/Test instead of D:\Test?

foxidrive

unread,
Jan 25, 2009, 11:37:10 PM1/25/09
to
On Sun, 25 Jan 2009 08:07:36 -0500, "Tom" <th...@aol.net> wrote:

>
>"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?

0 new messages