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)
38
if cmd == 'copytodir':
40
print "Usage: ostools.py copytodir FILES... DIR"
44
if not os.path.exists(todir):
46
if not os.path.isdir(todir):
47
print "Error: Destination is not a directory"
51
for possible_glob in argv:
52
files += glob.glob(possible_glob)
55
dest = os.path.join(todir, os.path.basename(src))
56
shutil.copy(src, dest)
57
print "Copied:", src, "=>", dest
63
print "Usage: ostools.py copytree FILES... DIR"
67
if not os.path.exists(todir):
69
if not os.path.isdir(todir):
70
print "Error: Destination is not a directory"
74
for possible_glob in argv:
75
files += glob.glob(possible_glob)
79
dest = os.path.join(todir, relative_path)
80
dest_dir = os.path.dirname(dest)
81
if not os.path.isdir(dest_dir):
83
shutil.copy(src, dest)
84
print "Copied:", src, "=>", dest
90
print "Usage: ostools.py remove [FILES...] [DIRS...]"
94
for possible_glob in argv:
95
filesdirs += glob.glob(possible_glob)
101
elif os.path.isfile(i):
105
print "Not found:", i
114
if __name__ == "__main__":