I have a "Dst Directory" directory in which there are files and folders, and I have a "src Directory" in which there are also files and folders. What I want to do is move the contents of "src Directory" to "Dst Directory" and overwrite anyfiles that exist with the same name. So, for example, "Src Directory \ file.txt" must be moved to the "Dst Directory" and overwrite the existing .txt file. The same applies to some folders, moving a folder, and merging contents with the same folder in the dst directory
I am currently using shutil.move to move the contents of src to dst, but it will not work if the files already exist and will not merge the folders; it will just put the folder in the existing folder.
Update: make things a little clearer; What I am doing is unzipping the archive into the Dst directory, and then moving the contents of the Src directory and unpacking, effectively updating the files in the zip archive. This will be repeated to add new files or new versions of files, etc. Therefore it is necessary to overwrite and merge
Solved: I solved the problem using distutils.dir_util.copy_tree (src, dst), this copies the folders and files from the src directory to the dst directory and overwrites / merges where necessary. Hope this helps some people!
Hope this makes sense, thanks!
python overwrite file move
Artharos Sep 14 '11 at 16:23 2011-09-14 16:23
source share