How do I make this bat file output the results to a .txt file?

723 views Asked by At
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_1" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_2" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_3" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_4" /s /m *.* /c "cmd /c Del @path" /d -08
forfiles /p "C:FILEPATH\TO\BE\DELETED\User_5" /s /m *.* /c "cmd /c Del @path" /d -08 

@echo off
@echo This purge was successfully completed on the date listed in the file name. 
>purgelog_%date:~-10,2%%date:~-7,2%%date:~-4,4%_.txt 

( command1
  command2
  ...
  commandN
)
1

There are 1 answers

0
lit On

If this is stored in my.bat, simply use redirection.

my.bat >my.txt

If you also want stderr to go into the same file, use:

my.bat >my.bat 2>&1

Note that this will not put the purgelog* information go into my.txt because its target file is explicitly specified.