Published: 22 May 2019 › Updated: 22 May 2019
Merge 2 directories in python
Merge 2 folers/directories using python
import os
import shutil
def move_merge_dirs(source_root, dest_root):
for path, dirs, files in os.walk(source_root, topdown=False):
dest_dir = os.path.join(
dest_root,
os.path.relpath(path, source_root)
)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
for filename in files:
destFile = os.path.join(dest_dir, filename)
if os.path.isfile(destFile):
continue
os.rename(os.path.join(path, filename), destFile)
for dirname in dirs:
# remove the source dir since all its contents were moved or are already existent
shutil.rmtree(os.path.join(path, dirname))
os.rmdir(source_root)
Sources:
https://stackoverflow.com/a/22588775/2287841
https://unix.stackexchange.com/questions/127712/merging-folders-with-mv/510724#510724
Leave Merge 2 directories in python to:
Read more #python posts
Best Posts From Octav
We have not curated any of octav's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Octav
- luarocks install loadcaffe: Error: No results matching query were found
- Tensorflow ImageDataGenerator 'DirectoryIterator' object has no attribute 'shape'
- How2: Swift 4 TF
- Etherum mining in Genesis - Review/Experience - Part IV - Last
- Merge 2 directories in python
- ssh not working/Connection refused on OrangePi/Debian
- California pepper origin Turkey & origin Spain & made in Romania
- Corporate
- Bugfixing before the release
- Bitcoin curve through a sound synth
- [Sherlock] Find the squirrel for 1 SBD
- When you get paid by Google to use their free trial
- Revolut is not encrypting its data!
- Revolut is not encrypting its data!
- When the wife gets home, but the husband is nowhere to be found
- Pokemon went
- Youtube autoplay fail
- Explaining steem
- Polysolar. George Iacobescu. Canary Wharf
- A successful trap