【发布时间】:2021-05-26 13:05:56
【问题描述】:
在批处理文件的帮助下,我可以从主目录和子目录中删除文件,但我发现很难删除其中的文件被删除后留下的空子目录。我已经编写了脚本,但它不适用于删除空子目录部分
我的批处理脚本
@echo off
Set _Extentions=".LOG"
Set _FolderList= "D:\FCS"
Set _FolderList=%_FolderList% "D:\SMSGateway\SMSLogs"
Set _NoOfDays=15
for %%s in (%_FolderList%) do (
for %%d in (%_Extentions%) do (
call :process_Deletion %%s %%d
)
)
:process_Deletion
IF [%1] == [] GOTO EndOfFun
set _ParaPath=%1
set _ParaExtn=%2
echo forfiles /P %_ParaPath% /S /m *%_ParaExtn% /D -%_NoOfDays% /C "cmd /c if @isdir==FALSE echo @path @fdate @ftime"
echo forfiles /P %_ParaPath% /S /m *%_ParaExtn% /D -%_NoOfDays% /C "cmd /c if @isdir==FALSE del @file"
echo for /f "delims=" %%d in ('dir %_FolderList% /s /b /ad ^| sort /r') do rd "%%d"
:EndOfFun
EXIT /B
我在这里做错了什么?请帮忙..
【问题讨论】:
标签: batch-file