windows - 用于从树中自动删除指定文件夹的批处理文件
问题描述
我正在尝试编写一个简单的工具来从 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
任何帮助将不胜感激。
解决方案
您需要使用一个for /r
循环遍历子文件夹的循环,如下所示:
for /R "C:\path\you\want" %%A IN (.) do (
if "%%A"=="Foldernameyouwant" rd Foldernameyouwant
您可以对提供的代码进行任何小的更改。
希望这可以帮助!
推荐阅读
- php - PHP5 - 变量在输出时生成foreach问题
- c++ - fstream.open() 在应该 c++ 时不会失败
- javascript - 未处理的拒绝(TypeError):传播不可迭代实例的无效尝试
- python - 如何上传完整的目录 Django?
- rest - 也可以属于其他资源的资源的 REST API 设计最佳实践
- python - 我想使用 PRAW 为我的 reddit 帖子设置天赋,有人可以提出解决方案吗?
- php - PHP GET 参数
- ruby-on-rails - Rails 5:使用 gteq 进行选择的 select_tag 选项
- powerbi - 如何在 Power BI 桌面中创建切片器截至(最新)日期
- u-sql - 将参数传递给 U-SQL 分区函数