I need to remotely delete sub folders older than 7 days, was able to find a syntax like this, but what it does is it loops through the subfolders and deletes the files in it older than 7 days. Any idea how can I delete the subfolders in xFOLDER older than 7 days as well?
PushD "\\IP ADDRESS\FOLDERA\FOLDERB\FOLDERC\FOLDERD\xFOLDER\" & ("forfiles.exe" /s /m "." /d -7 /c "cmd /c del @file") & PopD
You are almost there, just a few things need to be changed:
/S
forforfiles
, as you are interested in the immediate subdirectories ofxFOLDER
only;.
to*
;if
);forfiles
delivers a variable@isdir
which indicates whether the current item is a file (FALSE
) or a directory (TRUE
);del
deletes files, so to delete directories,rmdir
is required; switch/S
allows to delete even non-empty directories, switch/Q
prevents any prompts whether or not to delete;So this modified code should do what you want (written as multiple lines for legibility reasons):