我正在运行批处理文件脚本来删除特定文件夹中的文件。问题是如何在日志文件中记录删除的文件及其删除的日期时间,日志文件名称附带日期。
set folder="C:\test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
答案 0 :(得分:0)
@echo off
setlocal
set "YMD="
FOR /F "skip=1 tokens=1,2,3" %%A IN ('WMIC Path Win32_LocalTime Get Year^,Month^,Day /Format:table') DO (
if not defined Y set "YMD=%%B%%A%%C"
)
set folder="C:\test"
break>%YMD%.log
for /F "delims=" %%i in ('dir /b %folder%') do (
echo "%%~fi" deleted at %YMD% >>%YMD%.log
rmdir "%%i" /s/q || del "%%i" /s/q
)