Solved Batch forfiles help echoing based on success/failure

Custom built pc / Mobo: asus x99-deluxe lga...
December 16, 2015 at 09:34:17
Specs: Windows 10 Pro x64, I7-5820k Haswell-E 6-core @3.3 ghz | 16 GB DDR4
I have a batch file that browses to a shared director and deletes files older than a week.

PUSHD "\\server\SharedFolder\files"
forfiles -m *.* -d -8 -c "cmd /c del /q @path" 2> nul || ECHO NO FILES EXIST IN THE FOLDER OLDER THAN 1 WEEK (NO ACTION TAKEN)
POPD

If there are no files older than 1 week it will tell me so. If there are, it deletes them. Works fine.

I would like to change this so that when files are deleted it will say "Old files deleted" as well as when there are none to delete, which it already does.

Any ideas? Maybe an IF ELSE tied to the error stream somehow? Help is much appreciated.

~winipcfg

ASCII Question, Get an ANSI


See More: Batch forfiles help echoing based on success/failure

Report •

#1
December 16, 2015 at 15:32:32
✔ Best Answer
forfiles -m *.* -d -8 -c "cmd /c del /q @path" 2> nul 
IF NOT ERRORLEVEL 1 (ECHO Old files deleted) ELSE ECHO NO FILES EXIST IN THE FOLDER OLDER THAN 1 WEEK (NO ACTION TAKEN)

How To Ask Questions The Smart Way


Report •

#2
December 17, 2015 at 05:48:04
Perfect. Thank you again.

~winipcfg

ASCII Question, Get an ANSI


Report •
Related Solutions


Ask Question