我有以下批处理文件
@echo off
Del *.tmp /s /Q
Del *.temp /s /Q
Del Thumbs.db /s /Q
pause
我需要它以下列格式记录已删除的数据
数据量(KB)
删除了多少个文件
有人知道我可以使用的代码吗?
答案 0 :(得分:2)
@echo info about deleted files:
@for /f "delims=" %%a in ('dir /s /-c /a-s *.tmp^| findstr /i "File(s) Directory"') do (
@echo %%a
)
@del *.tmp /s /Q
答案 1 :(得分:1)
试试这个:
@echo off
setLocal enableDelayedExpansion
set filePattern=*.temp
set totalSize=0
for /F "tokens=* usebackq" %%a IN (`dir /b ^| findstr /R .!filePattern!$`) DO (
set size=%%~za
set /a totalSize=!totalSize! + !size!
)
del !filePattern! /s /Q
set /a totalSize=!totalSize! / 1024
echo Total size deleted (!filePattern!): !totalSize! KB
pause
您可能需要根据要删除的所需文件相应地更改!filePattern!
。除此之外,您可能必须将此批处理脚本放在与要删除的文件相同的目录中。