Windows XP Forefiles doesn't work

cvp

Joined
Nov 25, 2007
Messages
2
Reaction score
0
I need to automate deletion of folders..
Tried running this file from command prompt:
forfiles /p c:\Backup /s /m *.* /d -7 /c "cmd /c del @file"

This just attempts to delete files inside directory Backup but leaves the subdirectories intact. How do enable deletion of directories itself through this command?

Please help.
 
Joined
Feb 3, 2006
Messages
147
Reaction score
1
It is some time since I used DOS but my recollection is that del only deletes files and you need to use RD to remove directories (folders) and their contents. The following command will quietly remove Backup and all its subfolders:

rd /S /Q C:\Backup

followed by

md C:\Backup

to restore the empty folder Backup. If that is what you want then putting the two together in a batch file will do the job.
 

cvp

Joined
Nov 25, 2007
Messages
2
Reaction score
0
Hi

Thanx for the reply.
I did use forfiles /p c:\Backup /s /m *.* /d -7 /c "cmd /c rd @file"
However, got a response saying the 'directory is not empty'. I assumed directory has to be fully empty to use rd.
In my case, using command:
forfiles /p c:\Backup /s /m *.* /d -7 /c "cmd /c del @file"
removes files(not directories) directly under c:\Backup. It doens't recursively delete all the files inside subdirectories..in other word, doesn't empty the subdirectories. Therefore, I cannot use 'rd'.
Forefiles is maddening..How does this thing work exactly?
Im trying to find some solution to delete folders on basis of created date, from past 1 week & really going crazy.No one seems to help me:(
 
Joined
Feb 3, 2006
Messages
147
Reaction score
1
You are correct rd is not enough by itself. Try the following sequence of commands

del /S /Q c:\Backup\*.*

This one will, I think, remove all the files in Backup and all its subdirectories.
When you have done that you can use the two commands in my earlier post to clear the subdirectories

rd /S /Q C:\Backup
md C:\Backup

I have no suggestions as to how you select files according to their attributes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top