Created
November 28, 2016 19:34
-
-
Save jpstacey/7a4c27252120f74cc9c45e9ba30e9168 to your computer and use it in GitHub Desktop.
Copy a file, preserving all directories, with a horrible mixture of python shutil and os.system('mkdir -p')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Usage: copy_with_dirs.py <file> [file] [...] | |
# OR ... | xargs -d '\n' /tmp/copy_with_dirs.py | |
import shutil | |
import urllib | |
import sys | |
import os | |
for filename in sys.argv[2:]: | |
filename = urllib.unquote(filename) | |
print filename | |
new_filename = filename.replace( | |
'/home/jp/Music/library/', | |
'/media/jp/CHEWINGGUM/Kodi/' | |
) | |
os.system('mkdir -p "%s"' % os.path.dirname(new_filename)) | |
shutil.copyfile(filename, new_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment