请帮助纠正我的批处理代码,哪里出错了。目的是检查文件夹的位置,然后删除那些超过 180 天的文件。运行时,它不会弹出任何内容。
@echo off
setlocal EnableDelayedExpansion
Echo Delete Files older than 180 days
if exist "D:\HKvbrMain\Log\" (
echo Folder in Drive D
forfiles /p "D:\HKvbrMain\Log" /m *.* /d -180 /c "cmd /c del /f /q
@path"
) else (
echo Folder in Drive C
forfiles /p "%systemdrive%\HKvbrMain\Log" /m *.* /d -180 /c "cmd /c
del /f /q @path"
)
echo %errorlevel%
Pause
端局部
答案1
需要添加第二个条件才能使其起作用。
@echo off
setlocal EnableDelayedExpansion
Echo Delete Files older than 180 days
if exist "D:\HKvbrMain\Log\" (
echo Folder in Drive D
forfiles /p "D:\HKvbrMain\Log" /m *.* /d -180 /c "cmd /c del /f /q
@path"
) else (
if exist "%systemdrive%\HKvbrMain\Log\" (
echo Folder in Drive C
forfiles /p "%systemdrive%\HKvbrMain\Log" /m *.* /d -180 /c "cmd /c
del /f /q @path"
)
)
echo %errorlevel%
Pause