0

I am trying to delete log files older than 2 days recursively from a root folder. I wrote what I though would work but it also deletes folders if they are also older than 2 days. Can I modify this script to accomplish my goal of just purging files?, or is there a better way to skin this cat?

    set destinationDir=\\sqlbackupslas\SQLDataBackup\TESTING\CTM-A-Server
    pushd %destinationDir%
    echo "Deleting files from "%destinationDir%
    ForFiles /s /d -2  /c "cmd /c echo "deleting..." & echo @file"  <-- this is for testing, I'll change it to a delete
    popd
SteveLA
  • 9
  • 2
  • 2
    read the output of `forfiles /?`. Note the example in the very last line. – Stephan Nov 25 '20 at 18:58
  • 1
    As already mentioned by @Stephan, open a Command Prompt window, type `forfiles /?`, press the `[ENTER]` key, and read the usage information for the command you're using! You should clearly see `if @isdir==FALSE`. Your question is off topic, because you have clearly not read the standard built-in help for your problematic command. Future users will not benefit from any answers which tell them to read this essential information before posting a question or seeking assistance with a command. – Compo Nov 25 '20 at 19:21

0 Answers0