Page 1 of 1

Batch to delete specific files & folders

Posted: 05 Dec 2011 10:43
by MattProductions
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!

Re: Batch to delete specific files & folders

Posted: 05 Dec 2011 14:58
by ChickenSoup
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.

Re: Batch to delete specific files & folders

Posted: 05 Dec 2011 22:57
by MattProductions
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?

Re: Batch to delete specific files & folders

Posted: 06 Dec 2011 00:54
by orange_batch

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

Re: Batch to delete specific files & folders

Posted: 06 Dec 2011 01:18
by MattProductions
Thanks dude, it works now (after some tests)!

Hopefully it will keep on working!

Thanks thanks thanks!