Question

I have a file structure of images that is fairly flat although quite large (only goes 3-4 levels deep). In this structure I want to delete all folders that end with '.files' (no quotes).

Note that the files I want to delete are hidden.

I saw a relevant question (linked below) that suggested the following batch file (except using '_svn')

Command line tool to delete folder with a specified name recursively in Windows?

for /d /r . %d in (_svn) do @if exist "%d" rd /s/q "%d"

but it didnt work quite right for me. I got the following error when running at the directory I want to start: d" rd /s/q "d" was unexpected at this time.

So to be clear, I'm looking for a command that I can put into a batch file which I can cd to my desired directory, run the command, and delete directories beneath the current directory that end in '.files'

Any suggestions?

Was it helpful?

Solution

for /f %a in ('dir C:\yourdir\*.files /b /s /a:hd') do rd /s /q "%a"

or if running it from a batch file use 2 %'s

for /f %%a in ('dir C:\yourdir\*.files /b /s /a:hd') do rd /s /q "%%a"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top