www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simple delete directory tree?

reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
Does phobos have a simple way to delete a directory tree?
std.file.rmdir(path) and std.file.remove(path) don't seem to do it.
Apr 26 2013
parent reply "Andrej Mitrovic" <andrej.mitrovich gmail.com> writes:
On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
 Does phobos have a simple way to delete a directory tree?
 std.file.rmdir(path) and std.file.remove(path) don't seem to do 
 it.
Try rmdirRecurse
Apr 26 2013
parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Fri, 26 Apr 2013 22:55:36 +0200
"Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote:

 On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
 Does phobos have a simple way to delete a directory tree?
 std.file.rmdir(path) and std.file.remove(path) don't seem to do 
 it.
Try rmdirRecurse
I don't know how I managed to overlook that! Thanks :) Unfortunately, that's still choking with "Access is denied" on something inside a ".git" subdirectory.
Apr 26 2013
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/26/13, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:
 I don't know how I managed to overlook that! Thanks :)
I'd actually prefer if it was an enum or some other default parameter in the rmdir function itself: rmdir(string path, bool doRecurse = false);
Apr 26 2013
next sibling parent Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Fri, 26 Apr 2013 23:15:20 +0200
Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:

 On 4/26/13, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com>
 wrote:
 I don't know how I managed to overlook that! Thanks :)
I'd actually prefer if it was an enum or some other default parameter in the rmdir function itself: rmdir(string path, bool doRecurse = false);
Yea, that'd be kinda nice.
Apr 26 2013
prev sibling parent Marco Leise <Marco.Leise gmx.de> writes:
Am Fri, 26 Apr 2013 23:15:20 +0200
schrieb Andrej Mitrovic <andrej.mitrovich gmail.com>:

 On 4/26/13, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:
 I don't know how I managed to overlook that! Thanks :)
I'd actually prefer if it was an enum or some other default parameter in the rmdir function itself: rmdir(string path, bool doRecurse = false);
+1 -- Marco
Apr 28 2013
prev sibling next sibling parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Fri, 26 Apr 2013 17:01:43 -0400
Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:

 On Fri, 26 Apr 2013 22:55:36 +0200
 "Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote:
 
 On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
 Does phobos have a simple way to delete a directory tree?
 std.file.rmdir(path) and std.file.remove(path) don't seem to do 
 it.
Try rmdirRecurse
I don't know how I managed to overlook that! Thanks :) Unfortunately, that's still choking with "Access is denied" on something inside a ".git" subdirectory.
FWIW, This seems to work fine, at least on windows: import std.process; version(Windows) system(`rmdir /S /Q "`~path~`"`); else system(`rm -rf '`~path~`'`);
Apr 26 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-04-26 23:25, Nick Sabalausky wrote:

 FWIW, This seems to work fine, at least on windows:

 import std.process;
 version(Windows)
      system(`rmdir /S /Q "`~path~`"`);
 else
      system(`rm -rf '`~path~`'`);
That's cheating. -- /Jacob Carlborg
Apr 27 2013
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday, April 26, 2013 17:01:43 Nick Sabalausky wrote:
 On Fri, 26 Apr 2013 22:55:36 +0200
 
 "Andrej Mitrovic" <andrej.mitrovich gmail.com> wrote:
 On Friday, 26 April 2013 at 20:54:41 UTC, Nick Sabalausky wrote:
 Does phobos have a simple way to delete a directory tree?
 std.file.rmdir(path) and std.file.remove(path) don't seem to do
 it.
Try rmdirRecurse
I don't know how I managed to overlook that! Thanks :) Unfortunately, that's still choking with "Access is denied" on something inside a ".git" subdirectory.
That's an interesting problem to solve. If you can't legally remove a file, then rmdirRecurse either has to throw or ignore it. If it ignores it, the only way to know what went wrong would be to loop through the files that were removed (which could also blow up depending on the file permissions) and see what happens when you try and call remove or rmdir on them directly. On the other hand, if it throws, then you're basically forces to re-implement rmdirRecurse yourself and make it delete every file that you can if you want to at least delete the files that you can delete. Neither approach is exactly ideal. Maybe rmdirRecurse should be changed so that it ignores exceptions and returns whether it succeeded at removing everything or not (since it's void right now). However, if it _did_ fail due to a permissions issue, odds are that it would fail a _lot_ (especially if you're talking about a directory that you don't have permission to write to), and that would be very expensive. So, that might not be a good idea. We _could_ add another argument for telling it which behavior you wanted though. But I'm not sure that providing options like that is a good idea in the general case, particularly when you start considering all of the combinations of behaviors that functions like this could have. Still, it may be merited in this case. I don't know. - Jonathan M Davis
Apr 27 2013