Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107514
| From | Albert-Jan Roskam <sjeik_appie@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | RE: Remove directory tree without following symlinks |
| Date | 2016-04-23 09:34 +0000 |
| Message-ID | <mailman.8.1461404121.32212.python-list@python.org> (permalink) |
| References | <CACL+1aueH_scSTYW1Q6pGsZ92+8OWHB6tks3SqAAaU-wb6Ac4Q@mail.gmail.com> <DUB123-W362E7C64F347B92A74E34B83600@phx.gbl> |
> From: eryksun@gmail.com
> Date: Fri, 22 Apr 2016 13:28:01 -0500
> Subject: Re: Remove directory tree without following symlinks
> To: python-list@python.org
>
> On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam
> <sjeik_appie@hotmail.com> wrote:
> > FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read-
> > only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the
> > dir is not deleted either! A 'force' option would be a nice improvement.
>
> Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For
> example, see pip's rmtree_errorhandler:
>
> https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105
Thanks, that looks useful indeed. I thought about os.chmod, but with os.walk. That seemed expensive. So I used subprocess.call('rmdir "%s" /s /q' % dirname). That's Windows only, of course, but aside of that, is using subprocess less preferable?Fun fact: I used it to remove .svn dirs, just like what is mentioned in the pip comments :-)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 00:56 +1000
Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-22 11:09 -0400
Re: Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 03:14 +1000
RE: Remove directory tree without following symlinks Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-04-22 17:39 +0000
Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-22 13:28 -0500
RE: Remove directory tree without following symlinks Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-04-23 09:34 +0000
Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-23 15:22 -0500
Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-24 14:42 -0500
Re: Remove directory tree without following symlinks Paul Rubin <no.email@nospam.invalid> - 2016-04-23 01:13 -0700
Re: Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 20:24 +1000
Re: Remove directory tree without following symlinks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-23 23:37 +1200
Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-23 17:04 -0400
Re: Remove directory tree without following symlinks Nobody <nobody@nowhere.invalid> - 2016-04-23 17:29 +0100
Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-23 17:07 -0400
csiph-web