我创建一个脚本,删除路径中包含子文件夹的所有空文件夹。 现在我必须做,如果一个文件夹是在2天前创建的并且它是空的,那么它应该被删除,其他空文件夹的时间超过2天。如果不是,则不应该删除它。 而且我还需要/想要将已删除的文件夹写入日志中。 我用5个文件类型做了这个,但我不知道这个文件如何与文件夹一起工作。
我对Batch很新,所以我不知道该怎么办。 我检查了谷歌但结果与我的问题不符。 我希望有人可以帮助我。
这是我到目前为止编写的代码:
@echo off
::start path / Variables
set startdir="C:\Users"
::Initialize the Variable
set /a loop=0
::Directory c:\temp\ will be created, if the folder not exists
if not exist c:\temp\ md c:\temp\
::Create Logfile for Deleted Filetypes in C:\Log\LOG_Useless_File_Killer.txt
echo ----------------------------------- >> C:\Log\LOG_Useless_File_Killer.txt
echo Logfile from: %date% at %time% >> C:\Log\LOG_Useless_File_Killer.txt
echo. >> C:\Log\LOG_Useless_File_Killer.txt
::this 5 Filetypes are going to be deleted immediately
del C:\Users\Thumbs.db /f /q /s >> C:\Log\LOG_Useless_File_Killer.txt
del C:\Users\desktop.ini /f /q /s >> C:\Log\LOG_Useless_File_Killer.txt
del C:\Users\*.DS_Store /f /q /s >> C:\Log\LOG_Useless_File_Killer.txt
del C:\Users\*._DS_Store /f /q /s >> C:\Log\LOG_Useless_File_Killer.txt
del C:\Users\*.desktop /f /q /s >> C:\Log\LOG_Useless_File_Killer.txt
::Writes the directorys in c:\temp\tmp.txt.
dir /AD /b /s %startdir% > c:\temp\tmp.txt
::at goto start it will be start again
:start
::the Variable %loop% is increased by 1
set /a loop =%loop%+1
::at 5 --> goto exit
if %loop%==5 goto exit
::Under 5 --> goto start
else goto start
::deletes every empty folder which is written in C:\temp\tmp.txt
for /F "delims=" %%i in (c:\temp\tmp.txt) do rd "%%i"
::--> goto start and begins again
goto start
::%loop% has reached 5 --> exit
:exit
::Console window will be closed
exit
pause
exit