从目录中删除文件,并返回已删除的文件计数

问题描述:

亲爱的所有人,



我是批处理脚本的新手。我有要求,我想删除文件表格目录,其n天数据编码,并且Process将返回已删除文件的数量(生成日志)..



我几乎已经完成了使用Forfiles,但我不能返回已删除的文件数。



第二个任何人都可以提供异常处理的例子。





Bellow列出我的代码





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