Advertisement
galactus03

Untitled

Mar 5th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. """writing a script to copy the content of a folder having multiple folders with multiple files to a single folder"""
  2. #Importing modules
  3.  
  4. import os
  5. import shutil
  6.  
  7. #Getting destinatopn Folder
  8. def get_dest():
  9. get = True
  10. while get == True:
  11. dst_name = raw_input("Enter the destination folder : ")
  12. if os.path.exists(dst_name):
  13. print "FOLDER ALREADY EXISTS ."
  14. else :
  15. return dst_name
  16. get = False
  17.  
  18.  
  19. #Getting source folder
  20. def get_src():
  21. get = True
  22. while get == True:
  23. src_name = raw_input("Enter the name of the folder where files are : ")
  24. if os.path.exists(src_name):
  25. return src_name
  26. get = False
  27. else:
  28. print "Folder Doesn't exist. Try again .."
  29.  
  30. def copy_file(y):
  31. files = os.listdir(src+"/"+y)
  32. for i in files:
  33. shutil.copy(src+"/"+y+"/"+i,str(dest))
  34. print "File : " +src+"/"+ y +"/"+ i
  35. os.rename(str(dest)+'/'+i,y+" "+i)
  36.  
  37.  
  38.  
  39. print "Welcome to File Copy ..!"
  40. print "We will copy all the files from multiple folders to a single folder."
  41. src = get_src()
  42. dest = get_dest()
  43. os.mkdir(dest)
  44. dirs = os.listdir(src)
  45. for dir in dirs:
  46. copy_file(dir)
  47. print "DONE ..!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement