Deleting a folder via Batch file
Moderator: DosItHelp
Deleting a folder via Batch file
If i want to delete a folder, say it was named "Test Folder", on my H drive.....is this how i would write it because i am not having any luck:
CD H:\
ECHO
forfiles /p "H:\Neals Personal Info" /s /m Test*" /c "cmd /c Del Test*"
pause
Thank you in advance!
CD H:\
ECHO
forfiles /p "H:\Neals Personal Info" /s /m Test*" /c "cmd /c Del Test*"
pause
Thank you in advance!
Re: Deleting a folder via Batch file
Do you know the location of the folder?
Re: Deleting a folder via Batch file
If you know the folder name why are you using a File Mask with a wildcard?
The file mask could also match files so you should also look at using the @ISDIR variable.
The file mask could also match files so you should also look at using the @ISDIR variable.
Re: Deleting a folder via Batch file
Regardless of the above, there is one thing which appears quite obvious to me...
Do you really want to use a command named FORFILES to work with a DIRECTORY and then use DELETE as opposed to ReMoveDIRectory on it?
Do you really want to use a command named FORFILES to work with a DIRECTORY and then use DELETE as opposed to ReMoveDIRectory on it?
Re: Deleting a folder via Batch file
There are backup files/folders that are created every night at 11pm, and those files start with the word of "Test". So that is why i was using the wildcard. The location of those files are H:\Neals Personal\. So what i was really trying to do was every night i want to delete a backup folder that is a day old. So you all say i should just use the "DELETE" command? How would i specify the date parameters?
Re: Deleting a folder via Batch file
konjis1 wrote:How would i specify the date parameters?
Code: Select all
/D date Selects files with a last modified date greater
than or equal to (+), or less than or equal to
(-), the specified date using the
"MM/dd/yyyy" format; or selects files with a
last modified date greater than or equal to (+)
the current date plus "dd" days, or less than or
equal to (-) the current date minus "dd" days. A
valid "dd" number of days can be any number in
the range of 0 - 32768.
"+" is taken as default sign if not specified.
Re: Deleting a folder via Batch file
konjis1 wrote:There are backup files/folders that are created every night at 11pm, and those files start with the word of "Test". So that is why i was using the wildcard.
Please be more specific, are you deleting files which begin with Test located at "H:\Neals Personal"? or are you removing a directory beginning with Test located at "H:\Neals Personal"? or both of the above?konjis1 wrote:The location of those files are H:\Neals Personal\. So what i was really trying to do was every night i want to delete a backup folder that is a day old.
Re: Deleting a folder via Batch file
Well they are folders that have content. So the location is H:\Neals Personal\Test12345, where Test12345 contains the backup content. I am trying to delete the folder Test12345.
Re: Deleting a folder via Batch file
Code: Select all
@Echo Off & SetLocal
For /F "Tokens=*" %%A In ('Dir/B/AD/OD "H:\Neals Personal\Test*"') Do Set _D="%%~fA"
Echo( RD/S/Q %_D%&Pause