How to delete files only if the parent directory exists on the Windows command line?

I use this script package to delete files

FORFILES /P "X:\test" /S /M *.bak /C "CMD /C DEL @path"

However, an X drive is a resource in an active / passive cluster. I need to run a batch file on both nodes. Two questions...

  • Is this the best method?
  • I want the package to look for an X disk before deleting files - do you know about that? I do not want it to work on a passive cluster, because the X-disk will not be on it.
+3
source share
2 answers

It would be much faster to just use DEL instead of FORFILES. You can check if the root path exists using IF EXIST.

if exist "x:\test\*.bak" del /q /s "x:\test\*.bak"
+8
source

. , . , , .

0

All Articles