从目录中删除文件,并返回已删除的文件计数 [英] Remove Files from directory, and return deleted files count

查看:90
本文介绍了从目录中删除文件,并返回已删除的文件计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我是批处理脚本的新手。我有要求,我想删除文件表格目录,其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

推荐答案

这篇关于从目录中删除文件,并返回已删除的文件计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆