At least on windows, shutil.move
a folder containing readonly files to another drive will fail. It fails because move
is implemented with a copy
followed by a rmtree
. In the end, it's the rmtree
trying to delete non writable files.
Currently I work around it by first setting the stat.S_IWUSER
for all (nested) files, but now I should still restore the original stat
afterwards:
def make_tree_writable(source_dir):
for root, dirs, files in os.walk(source_dir):
for name in files:
make_writable(path.join(root, name))
def make_writable(path_):
os.chmod(path_, stat.S_IWUSR)
def movetree_workaround(source_dir, target_dir):
make_tree_writable(source_dir)
shutil.move(source_dir, target_dir)
So I wonder: is this the way? Is there a shutil2
in the making that I could use? Can I be of any help there?