Batch to delete specific files & folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MattProductions
Posts: 3
Joined: 05 Dec 2011 10:24

Batch to delete specific files & folders

#1 Post by MattProductions » 05 Dec 2011 10:43

Hello

I program a lot and the program I use creates a lot of useless and large sized files to debug the applications and games I make.

Could you guys please make a batch file that deletes some files and folders in the underlying maps?

This has to be deleted

- "Debug" folder (and underlying files / folders)
- "Release" folder (and underlying files / folders)
- "ipch" folder (and underlying files / folders)
- All .sdf files

It has to search in all underlying folders. I'll give an example
c:/location of batch/../../../debug/
It has to work even if it's not in the same folder.

Is this possible to create that for me?
I would be really helpfull to me.

Thanks!

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Batch to delete specific files & folders

#2 Post by ChickenSoup » 05 Dec 2011 14:58

I'm no expert but, in the batch file you could use something like this possibly:

Code: Select all

for /f "tokens=*" %%a in ('dir /ad /b /s ^|findstr /e /i /r "\\Debug\>"') do rd /s /q %%a
for /f "tokens=*" %%a in ('dir /ad /b /s ^|findstr /e /i /r "\\Release\>"') do rd /s /q %%a
for /f "tokens=*" %%a in ('dir /ad /b /s ^|findstr /e /i /r "\\ipch\>"') do rd /s /q %%a
for /f "tokens=*" %%a in ('dir /b /s *.sdf') do del /s /q %%a


But don't take my word for it. This is also relative the directory it executes from.

MattProductions
Posts: 3
Joined: 05 Dec 2011 10:24

Re: Batch to delete specific files & folders

#3 Post by MattProductions » 05 Dec 2011 22:57

I've tried that code, but without any success...
I've placed it in the same folder, a folder above, etc.... Same results.

The command box pops up for 0.5 seconds and I was able to read that "the system can't find ... (I missed the other half)".

Maybe that's usefull?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Batch to delete specific files & folders

#4 Post by orange_batch » 06 Dec 2011 00:54

Code: Select all

for /f "delims=" %%a in ('dir /ad /b /s') do (
if "%%~nxa"=="Debug" rd /s /q "%%a"
if "%%~nxa"=="Release" rd /s /q "%%a"
if "%%~nxa"=="ipch" rd /s /q "%%a"
)
del /f /s /q *.sdf >nul 2>&1

MattProductions
Posts: 3
Joined: 05 Dec 2011 10:24

Re: Batch to delete specific files & folders

#5 Post by MattProductions » 06 Dec 2011 01:18

Thanks dude, it works now (after some tests)!

Hopefully it will keep on working!

Thanks thanks thanks!

Post Reply