18 November 2011

Dos Command for Batch Processing

When you need to process multiple files in a batch file use forfiles.exe

For example, to recursively delete all files in the directory U:\Downloads older than 7 days:

  1. Open Notepad
  2. Type the following:
    forfiles.exe /p "U:\Downloads" /m *.* /s /D -7 /c "cmd /c del @path /q"
    Where:
    /p [path]= path
    /m = File select mask. In this case *.* i.e. all files.
    /s = recursive
    /D [date/+dd/-dd]= select files with last modified date. In this case less than or equal to current date minus 7 days.
    /c [command]= command to run for each file surrounded by quotes. Switches can be used in the command string (See more information).
  3. Save the file as deletedownloads.bat (change file type to all files)
  4. Run it by double clicking on it.

More Information

No comments:

Post a Comment