首页 > 解决方案 > 用于从树中自动删除指定文件夹的批处理文件

问题描述

我正在尝试编写一个简单的工具来从 Windows 系统中删除垃圾 Mac 文件,但是,我遇到了问题,因为指定的文件夹 (.fseventsd) 仍然存在,无论我做什么。下面是批处理文件,具体关注的区域是 :.fseventsd 部分中的 rmdir 命令。

rem @echo off
cls
cd \

:.fseventsd
echo Searching for '.fseventsd' folders.
rmdir /S /Q ".fseventsd" 2> nul
if errorlevel 1 echo No '.fseventsd' folders were found.
goto :.DS_STORE
if errorlevel 0 echo All '.fseventsd' folders have been deleted.

:.DS_STORE
echo.
echo Searching for '.DS_STORE' files.
del /s /q /f /a:rash .DS_STORE 2> nul
if errorlevel 1 echo No '.DS_STORE' files were found.
goto ._.*
if errorlevel 0 echo All '.DS_STORE' files have been deleted.

:._.*
echo.
echo Searching for '._.*' files.
del /s /q /f /a:rash ._.* 2> nul
if errorlevel 1 echo No '._.*' files were found.
goto END
if errorlevel 0 echo All '._.*' files have been deleted.
echo.

:END
echo All tasks have now been finished.
pause

任何帮助将不胜感激。

标签: windowsbatch-filecmdrmdir

解决方案


您需要使用一个for /r循环遍历子文件夹的循环,如下所示:

for /R "C:\path\you\want" %%A IN (.) do (
     if "%%A"=="Foldernameyouwant" rd Foldernameyouwant

您可以对提供的代码进行任何小的更改。

希望这可以帮助!


推荐阅读