Deleting files & folder with a batch file
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!
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.
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
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
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 *.*
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
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement