How do I delete files only if the parent directory exists in the Windows command prompt?
batch-file, cmd, windows
Solution
It would be much faster to simply use DEL instead of FORFILES. You can test if the root path exists using IF EXIST.
if exist "x:\test\*.bak" del /q /s "x:\test\*.bak"
Problem
I'm using this batch script to delete files ``` FORFILES /P "X:\test" /S /M *.bak /C "CMD /C DEL @path" ``` However, the X drive is a resource on an active/passive cluster. I have to run the batch file on both nodes. Two questions... - Is this the best method? - I want the batch to look for the X drive before deleting the files - do you know of a way? I don't want it to run on the passive cluster because the X drive won't be on it.