Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I am new to batch scripting. I have requirement, I want to delete files form directory, whose are n-days datamodified, and Process will return count of deleted files (genrating log)..

I have almost done with this by using Forfiles, but i cant return deleted files count.

Second can anyone provide example of exception handling.


Bellow listed my code


@echo off
set max_days=7

set configPath=E:\Reports\fileConfig.txt

echo Configuration file located in %configPath%
echo last modified days : %max_days%
echo -------------------------------
echo.

for /f "tokens=*"  %%i in (%configPath%) do (

   call :ProcessLine %%i

)

pause
goto :EOF

REM Process each document
:ProcessLine

SETLOCAL  EnableDelayedExpansion

set line= "%*"

echo Removing files from directory : %line%

:: remove files from %path%
forfiles -p %line% -m *.* -d -%max_days% -c "cmd  /c echo. & echo Deleting file @file : file size = @fsize & del /q @path  "

echo ===============================
echo.

ENDLOCAL

goto :EOF

:EOF
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900