Batch file for automatically deleting specified folders from within tree

271 Views Asked by At

I am trying to write a simple tool to delete junk Mac files from a Windows system, however, I am having trouble as a specified folder (.fseventsd) remains, no mater what I do. Below is the batch file, and the specific area of concern is the rmdir command in the :.fseventsd section.

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

Any help would be greatly appreciated.

1

There are 1 best solutions below

0
On

You need to use a for /r loop which loops through subfolders just like this:

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

You can make any minor changes you want to the code provided.

Hope this helps!