Advertisement
1400_SpaceCat

FileMover

Sep 12th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import os,shutil
  2.  
  3. def checkFileFormat(fileFormat,sourceDir):
  4.                
  5.         for i in range(len(os.listdir(sourceDir))):
  6.             File = os.listdir(sourceDir)[i]
  7.             (fn,ff) = File.split(".")
  8.             xdir = fileFormat+"/"
  9.  
  10.             if ( ff == fileFormat ):
  11.                 src_dir = sourceDir+str(File)
  12.                 dst_dir = xdir+str(File)
  13.                 shutil.move(src_dir,dst_dir)
  14.  
  15.             else:
  16.                 print("File format does not exists!")
  17.                 break
  18.  
  19.         print("**DONE**")
  20.         exit()
  21.  
  22. while( True ):
  23.         file_format = input("File format: ")
  24.         source_dir = str(input("Source directory: "))
  25.         source_dir += "/"
  26.  
  27.         if ( file_format.isdigit() ):
  28.                 print("Numbers is not a format!")
  29.         else:
  30.                 break
  31.  
  32.         if ( not os.path.exists(source_dir) ):
  33.                 print("Directory doesn't exists!")
  34.         else:
  35.                 break
  36.  
  37. while( True ):
  38.         try:
  39.                 checkFileFormat(file_format,source_dir)
  40.         except Exception:
  41.                 pass
  42.         else:
  43.                 exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement