diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-01-12 09:48:02 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-01-12 09:48:02 +0000 |
commit | 51c90d79b9f67a2ce10c4e7a824541f6d05a324c (patch) | |
tree | 5510e0b8c6b52be7127ada3633082aaa4af40e37 /fs/utils.py | |
parent | 9a8ca7fa4a9a78a763a4f4ed402bb9d195d660fe (diff) | |
download | pyfilesystem-51c90d79b9f67a2ce10c4e7a824541f6d05a324c.tar.gz |
Added a remove_all function to utils
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@738 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/utils.py')
-rw-r--r-- | fs/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/fs/utils.py b/fs/utils.py index 8e1e445..5e9612c 100644 --- a/fs/utils.py +++ b/fs/utils.py @@ -253,6 +253,23 @@ def copydir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=6 chunk_size=chunk_size) +def remove_all(fs, path): + """Remove everything in a directory. Returns True if successful. + + :param fs: A filesystem + :param path: Path to a directory + + """ + fs.tree() + sub_fs = fs.opendir(path) + for sub_path in sub_fs.listdir(): + if sub_fs.isdir(sub_path): + sub_fs.removedir(sub_path, force=True) + else: + sub_fs.remove(sub_path) + return fs.isdirempty(path) + + def copystructure(src_fs, dst_fs): """Copies the directory structure from one filesystem to another, so that all directories in `src_fs` will have a corresponding directory in `dst_fs` |