• Emptying multiple folders at once without deleting them
    28 replies, posted
Alright, I have about 970 folders, some of them empty, some of them packed. I need to empty all these folders simultaneously without actually deleting them. Basically, I want all these folders to be empty. With one click. Any of you guys know a way to whip up a batch file that can do this?
[code]del */* /q rmdir */* /s /q[/code] Place it besides the folders or prepend the path to the asterisk. The first command deletes all sub-files, and the second removes all sub-directories - if I am not mistaken; better try it out first before putting it to real use.
[QUOTE=ZeekyHBomb;27216392][code]del */* rmdir */*[/code] Place it besides the folders or prepend the path to the asterisk. The first command deletes all sub-files, and the second removes all sub-directories - if I am not mistaken; better try it out first before putting it to real use.[/QUOTE] Didn't seem to work, all files retained.
I tried fixing it, but I give up. If you happen to have MSYS installed, or have no problems installing it, use this: [code]bash -c "rm -R */* &> /dev/null"[/code]
[QUOTE=ZeekyHBomb;27216877]I tried fixing it, but I give up. If you happen to have MSYS installed, or have no problems installing it, use this: [code]bash -c "rm -R */* &> /dev/null"[/code][/QUOTE] Installed MSYS and MiniGW and that didn't work either. It's pretty frustrating that I can't do this; the previous IT Manager here had a simple script that did the trick but he's long gone, and doing this by hand would really suck.
Works fine on my Linux-Box. What's the error when run from a terminal?
Going on that he asked if it was possible in batch, i THINK he may be running windows...
But MSYS provides bash and rm.
[QUOTE=Tobba;27217976]Going on that he asked if it was possible in batch, i THINK he may be running windows...[/QUOTE] Quite.
Where are all these folders; are they in a single directory? If so, are there folders in this directory that should not be emptied? I could whip something up in python if you can tell me exactly how to target the folders to be emptied.
You guys are over-complicating this. [code] del foobar /s /q [/code] This will empty the directory foobar and all sub-directories. Just put it (.bat) besides your main directory, change "foobar" for whatever, and run it.
[QUOTE=Xeon06;27227523]You guys are over-complicating this. [code] del foobar /s /q [/code] This will empty the directory foobar and all sub-directories. Just put it (.bat) besides your main directory, change "foobar" for whatever, and run it.[/QUOTE] This works because DEL command can only delete files and not folders. For deleting folders there's separate function called RMDIR.
Umm, you need to specify if these folders you need to empty are all contained into one, and if you basically want to keep the "1st" level ones only. If thats it I can throw a python script together if you want.
[QUOTE=sim642;27231179]This works because DEL command can only delete files and not folders. For deleting folders there's separate function called RMDIR.[/QUOTE] Yes? It does exactly what he wants.
[QUOTE=bootv2;27253594]I'd imagine he'd want subfolders deleted too.[/QUOTE] [QUOTE=1337_f00;27216220]Alright, I have about 970 folders, some of them empty, some of them packed. I need to empty all these folders simultaneously [b]without actually deleting them[/b]. Basically, I want all these folders to be empty. With one click. Any of you guys know a way to whip up a batch file that can do this?[/QUOTE]
He really didn't say one way or the other.
You cant. Its impossible. The world as we know it suffers greatly because of this very problem. Sorry bro, its irreversible. :ohdear:
I could write a C# application for you in like five minutes if you still need help. [editline]18th January 2011[/editline] Pseudocode: [cpp] List<string> files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories); foreach(string f in files){ File.Delete(f); } [/cpp] The method names and stuff aren't correct but that should do it.
[url=http://www.foxprods.net/experimentalists/remover.exe]Here you go[/url] It'll delete every file in its current directory, ever subdirectory, and every subdirectory of the subdirectories etc.
[QUOTE=geel9;27514457][url=http://www.foxprods.net/experimentalists/remover.exe]Here you go[/url] It'll delete every file in its current directory, ever subdirectory, and every subdirectory of the subdirectories etc.[/QUOTE] While I normally don't trust random executables from strangers, this one in particular is giving me the heebie-jeebies even more.
For the love of god guys I already provided him with exactly what he wanted.
[QUOTE=Shammah;27519701]While I normally don't trust random executables from strangers, this one in particular is giving me the heebie-jeebies even more.[/QUOTE] [cpp]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories); foreach (string f in files) { if (!f.Contains("remover.exe")) { File.Delete(f); } } } } } [/cpp] herp
[QUOTE=geel9;27520358][cpp]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories); foreach (string f in files) { if (!f.Contains("remover.exe")) { File.Delete(f); } } } } } [/cpp] herp[/QUOTE] Why is the name of the executable hard-coded into the program?
[QUOTE=sim642;27521974]Why is the name of the executable hard-coded into the program?[/QUOTE] Because I coded it in literally three minutes.
[QUOTE=geel9;27523822]Because I coded it in literally three minutes.[/QUOTE] Process.GetCurrentProcess().ProcessName()
Now you're just being nitpicky. He obviously just wanted to show of how he can do it in 3 minutes in C#. A bit childish maybe but we all do it and it's ok. Why would he bother with the filename? What are the odds that someone will rename the .exe file?
[QUOTE=Darwin226;27525333]Now you're just being nitpicky. He obviously just wanted to show of how he can do it in 3 minutes in C#. A bit childish maybe but we all do it and it's ok. Why would he bother with the filename? What are the odds that someone will rename the .exe file?[/QUOTE] I wasn't showing off.
No need to act so modest about it :3:
Sorry, you need to Log In to post a reply to this thread.