我想在下面使用此脚本清除“ C:\ Storage \ Websites \ Site1”等网站中的“ tmp”和“缓存”文件夹。
它尝试删除“ C:\ Storage \ Websites \ Site1 \ tmp”和“ C:\ Storage \ Websites \ Site1 \ cache”中的文件和子文件夹。
没错,但是它还会尝试删除“ C:\ Storage \ Websites \ Site1 \ MySpecialLittleProgram \ tmp”和“ C:\ Storage \ Websites \ Site1 \ MySpecialLittleProgram \ cache”中的文件和子文件夹”。
哪有错 它只应清理网站根目录中的“ tmp”和“ cache”文件夹,而不清理其他子文件夹中的文件夹。
如果删除“ dir / a:d / b / s tmp缓存”中的/ s参数,它将找不到任何内容。
我该怎么做?
(如果有人复制了我的脚本,我已经在文件删除部分和文件夹删除部分中删除了/ q参数。)
@echo off
call:CleanUp "C:\Storage\Websites"
echo.&pause&goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:CleanUp
IF EXIST %~1 (
cd /d %~1
FOR /f "tokens=*" %%i in ('dir /a:d /b /s tmp cache') DO (
echo %%i
::DELETING FILES I FOLDERS AND SUBFOLDERS
del %%i /s
::DELETING NOW EMPTY FOLDERS AND SUBFOLDERS
FOR /D %%p IN ("%%i\*.*") DO rmdir "%%p" /s
)
)
goto:eof
更新:
我将代码更新为(现在正在运行):
@echo off
call:CleanUp "C:\Storage\Web"
call:CleanUp "C:\Storage\Web-IIS"
goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:CleanUp
IF EXIST %~1 (
cd /d %~1
FOR /f "tokens=*" %%i in ('dir /a:d /b') DO (
IF EXIST %%i\tmp (
del %%i\tmp /s /q
FOR /D %%p IN ("%%i\tmp\*.*") DO rmdir "%%p" /s /q
)
IF EXIST %%i\cache (
del %%i\cache /s /q
FOR /D %%p IN ("%%i\cache\*.*") DO rmdir "%%p" /s /q
)
)
)
goto:eof
这应该删除这两个位置中的文件:
@echo off
del "C:\Storage\Websites\Site1\tmp\*.*" /a /s
del "C:\Storage\Websites\Site1\cache\*.*" /a /s
根据您的评论,这可能是您需要做的:echo
在测试关键字以查看控制台上将要执行的命令后将其删除。
@echo off
cd /d "C:\Storage\Websites"
for /d %%a in (*) do (
for %%b in (tmp cache) do (
pushd "%%~fa\%%b" 2>nul && (echo rd /s /q "%%~fa\%%b" 2>nul & popd)
)
)
pause
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句