我制作了一个脚本,删除路径中带有子文件夹的所有空文件夹。
现在我必须做的是,如果一个文件夹是 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
Pradeep https://stackoverflow.com/users/153541/pradeep关于最好的方法是文件的说法绝对正确。
要删除文件夹,请尝试以下操作:
FORFILES -p "" /D -15 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"
/D 表示天数,您可以使用命令参数来满足确切的要求。
您还可以使用环境变量,这样您就可以轻松地仅删除当前登录用户的文件。例如,您可以使用%HOMEPATH%\Desktop
进入当前用户的桌面。更多环境变量here https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)