Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
April 26, 2013 Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
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. |
April 26, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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
|
April 26, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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.
|
April 26, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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); |
April 26, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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.
|
April 26, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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~`'`); |
April 27, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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 |
April 28, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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
|
April 28, 2013 Re: Simple delete directory tree? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 |
Copyright © 1999-2021 by the D Language Foundation