Created
February 14, 2012 13:01
-
-
Save varepsilon/1826633 to your computer and use it in GitHub Desktop.
Create directory with symlinks to other files translating directory structure to filenames.
This file contains 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 python3 | |
import sys | |
import os | |
def make_detailed_fname(basedir, dirpath, fname): | |
return dirpath[len(basedir):].replace('!', '').replace(' ', '_')\ | |
.replace('/', '_') + '_' + fname | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print("Usage: {} src_dir dst_dir".format(sys.argv[0]), file=sys.stderr) | |
sys.exit(1) | |
for dirpath, subdirs, files in os.walk(sys.argv[1]): | |
for f in files: | |
os.symlink(os.path.join(dirpath, f), | |
os.path.join(sys.argv[2], | |
make_detailed_fname(sys.argv[1], dirpath, f)) | |
) |
This file contains 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 python3 | |
import sys | |
import os | |
def make_detailed_fname(basedir, dirpath, fname): | |
return dirpath[len(basedir):].replace('!', '').replace(' ', '_')\ | |
.replace('/', '_') + '_' + fname | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print("Usage: {} src_dir dst_dir".format(sys.argv[0]), file=sys.stderr) | |
sys.exit(1) | |
for dirpath, subdirs, files in os.walk(sys.argv[1]): | |
for f in files: | |
os.symlink(os.path.join(dirpath, f), | |
os.path.join(sys.argv[2], | |
make_detailed_fname(sys.argv[1], dirpath, f)) | |
) |
This file contains 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 python3 | |
import sys | |
import os | |
def make_detailed_fname(basedir, dirpath, fname): | |
return dirpath[len(basedir):].replace('!', '').replace(' ', '_')\ | |
.replace('/', '_') + '_' + fname | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print("Usage: {} src_dir dst_dir".format(sys.argv[0]), file=sys.stderr) | |
sys.exit(1) | |
for dirpath, subdirs, files in os.walk(sys.argv[1]): | |
for f in files: | |
os.symlink(os.path.join(dirpath, f), | |
os.path.join(sys.argv[2], | |
make_detailed_fname(sys.argv[1], dirpath, f)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment