-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinkdir
executable file
·35 lines (28 loc) · 986 Bytes
/
linkdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# vi: syntax=python
# make softlinks to all files in a directory to the current directory
# TODO: document suffix syntax and usage
# TODO: option for crash on errors?
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
import sys, os
curdir = os.getcwd()
for dirname in sys.argv[1:]:
if '=' in dirname:
suffix, dirname = dirname.split('=')
else:
suffix = None
dirname = os.path.expanduser(dirname)
for filename in os.listdir(dirname):
oldname = os.path.join(dirname, filename)
if suffix:
root, ext = os.path.splitext(filename)
newname = os.path.join(curdir, f"{root}-{suffix}{ext}")
else:
newname = os.path.join(curdir, filename)
try:
os.symlink(oldname, newname)
print("Linked", oldname, "to", newname)
except OSError:
print("Couldn't make link from", oldname, "to", newname)