forked from Xinglab/rmats-turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp_with_prefix.py
31 lines (23 loc) · 866 Bytes
/
cp_with_prefix.py
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
import argparse
import os.path
import shutil
def parse_args():
parser = argparse.ArgumentParser(
description=('add a prefix to each file as it is copied'
' into a destination directory'))
parser.add_argument('prefix', help='the prefix to add to each file')
parser.add_argument('dest_dir',
help='the destination directory to copy files to')
parser.add_argument('files', nargs='+', help='the files to copy')
return parser.parse_args()
def cp_with_prefix(args):
for f_path in args.files:
basename = os.path.basename(f_path)
prefixed = '{}{}'.format(args.prefix, basename)
dest_path = os.path.join(args.dest_dir, prefixed)
shutil.copy(f_path, dest_path)
def main():
args = parse_args()
cp_with_prefix(args)
if __name__ == '__main__':
main()