Jump to content
  • Advertisement
Sign in to follow this  
_Sigma

Deleting files & folder with a batch file

This topic is 4616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I hate to admit this, but I am completly inept when it comes to using batch files. I looked on google (perhaps looked in the wrong spot?) but I was unable to find an answer to my problem. Pretty much the issue is this: I have a folder structure like Docs[this is the top folder] +----Folder 1 +----Folder 2 +----Folder n +----File 1 +----File 2 +----File n +----myBatchFile So I want to write a batch file that deletes everything, including the subfolders and files, except for the batch file. So how do I go about pulling this off? (yes i'm looking for full code. Provided someone wants to give it to me, as I am having a hard time pulling this off =( ) Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by _Sigma
I hate to admit this, but I am completly inept when it comes to using batch files.

Don't worry, there are only 7 good batch programmers in the entire universe. Not because batch is some arcane super-powerful thing only the uber-gurus know about either. Batch is so frustratingly incompetent at anything except running a few programs in sequence (and it even screws that up if you're not careful), it takes years of torurous practice to get good at batch. And even then, you'll be writing batch files that write batch files that write more batch files that write yet more batch files that finally executes and... runs 7 commands with a few trivial arguments. 20 hours of development time wasted, considering you could have run the 7 commands faster by hand. Or written, debugged and tested a C program in 15 minutes that does the same thing, only doesn't take 2 hours to run (only 2 seconds). Pretty sad that you can do the same thing on UNIX in 4 seconds.. Oops, I ranted. Sorry, you brought up some very frustrating memories from the dark ages.

Oh yeah, look at the deltree command.

Share this post


Link to post
Share on other sites
I'm guessing that myBatchFile is the file you want to write. It would be a lot easier if you put it in the parent folder(which also contains the Docs folder).
Then, the batch file would look like this :

@echo off
rd /S /Q Docs
:: If you want the Docs folder to remain there after delete un-comment next line
:: md Docs

Share this post


Link to post
Share on other sites
You can give your batch file the Hidden attribute (right-click in Explorer or whatever), then it won't delete itself when you do a del *.*

Share this post


Link to post
Share on other sites
Quote:
Original post by Mocanu Razvan
I'm guessing that myBatchFile is the file you want to write. It would be a lot easier if you put it in the parent folder(which also contains the Docs folder).
Then, the batch file would look like this :

@echo off
rd /S /Q Docs
:: If you want the Docs folder to remain there after delete un-comment next line
:: md Docs


Actually this turned out to work the best. Thanks. Now how do I get it to run another bat file from myBatchFile?

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by _Sigma
Now how do I get it to run another bat file from myBatchFile?

Thanks


Use "call other.bat" (and optionally pass arguments to it just like on the command line)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!