3
"""Cross-platform os tools: files/directories manipulations
9
ostools.py copytodir FILES... DIR
10
copy files to specified directory
12
ostools.py copytree FILES... DIR
13
copy files to specified directory keeping relative paths
15
ostools.py remove [FILES...] [DIRS...]
16
remove files or directories (recursive)
25
if not os.path.exists(dirname):
27
if not os.path.isdir(dirname):
28
print "Error: Destination is not a directory", dirname
45
if cmd == 'copytodir':
47
print "Usage: ostools.py copytodir FILES... DIR"
51
retcode = makedir(todir)
56
for possible_glob in argv:
57
files += glob.glob(possible_glob)
60
dest = os.path.join(todir, os.path.basename(src))
61
shutil.copy(src, dest)
62
print "Copied:", src, "=>", dest
68
print "Usage: ostools.py copytree FILES... DIR"
72
retcode = makedir(todir)
77
for possible_glob in argv:
78
files += glob.glob(possible_glob)
82
dest = os.path.join(todir, relative_path)
83
dest_dir = os.path.dirname(dest)
84
retcode = makedir(dest_dir)
87
shutil.copy(src, dest)
88
print "Copied:", src, "=>", dest
94
print "Usage: ostools.py remove [FILES...] [DIRS...]"
98
for possible_glob in argv:
99
filesdirs += glob.glob(possible_glob)
105
elif os.path.isfile(i):
109
print "Not found:", i
113
if cmd == "basename":
115
print "Usage: ostools.py basename [PATH | URL]"
119
print os.path.basename(path)
124
print "Usage: ostools.py makedir DIR"
127
retcode = makedir(argv.pop())
137
if __name__ == "__main__":