开发者

Python: Overwriting a directory with another directory containing the same files

开发者 https://www.devze.com 2023-01-18 17:53 出处:网络
I\'m trying to overwrite a directory with another directory that contains the same files. I\'v开发者_JAVA百科e tried using distutils.dir_util.copy_tree(src, dst) but it tried to make a directory for d

I'm trying to overwrite a directory with another directory that contains the same files. I'v开发者_JAVA百科e tried using distutils.dir_util.copy_tree(src, dst) but it tried to make a directory for dst instead. The objective is to overwrite the directory and its contents silently. Is there any other way to do so?


Edit: This rigamarole is apparently not necessary; see the OP's answer for the reason.

You'll probably want to first rename the destination directory to something else. If that goes okay, then copy the source directory to the original name of the destination directory. Then, if that worked, delete the destination directory from its new location.

You should first create a temporary directory into which to move the destination directory using tempfile.mkdtemp.


oops... Turns out that distutils.dir_util.copy_tree(src, dst) works.

It's just that I got my directory path from environment variables and '\n' was stuck at the back of my path.

Adding in a .strip() to my path variable solved the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号