-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoryCopy.py
47 lines (35 loc) · 1.18 KB
/
DirectoryCopy.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Design automation script which accept two directory names. Copy all files from first directory
into second directory. Second directory should be created at run time.
"""
import shutil;
import sys;
import os;
def dirCopy(sourceDir,targetDir):
flag=os.path.isabs(sourceDir);
if flag == False:
sourceDir=os.path.abspath(sourceDir);
exists=os.path.exists(sourceDir);
if exists:
os.mkdir(targetDir);
for dirName, subDir, files in os.walk(sourceDir):
cnt=0;
for fname in files:
fname = os.path.join(dirName, fname);
shutil.copy(fname,targetDir);
cnt=+1;
if cnt == 0:
print("\nNo files found to copy.");
else:
print("files has been copied successfully!!!\n please go to directory and have a look.")
else:
print("Invalid path");
def main():
try:
dir1=sys.argv[1];
dir2=sys.argv[2];
dirCopy(dir1,dir2);
except Exception as E:
print("Exception occured: ",E)
if __name__ == "__main__":
main();