@@ -15,31 +15,31 @@ def getNumberOfFilesInFolderRecursively(start_path = '.'):
15
15
for f in filenames :
16
16
fp = os .path .join (dirpath , f )
17
17
if (os .path .isfile (fp )):
18
- numberOfFiles += 1
18
+ numberOfFiles += 1
19
19
return numberOfFiles
20
20
21
21
22
22
def getNumberOfFilesInFolder (path ):
23
- return len (os .listdir (path ))
23
+ return len (os .listdir (path ))
24
24
25
25
26
26
def log (logString ):
27
- print (strftime ("%H:%M:%S" , localtime ()) + ": " + logString )
27
+ print (strftime ("%H:%M:%S" , localtime ()) + ": " + logString )
28
28
29
29
30
30
def moveFile (file , destination ):
31
- extension = os .path .splitext (file )[1 ][1 :].upper ()
32
- sourcePath = os .path .join (root , file )
31
+ extension = os .path .splitext (file )[1 ][1 :].upper ()
32
+ sourcePath = os .path .join (root , file )
33
33
34
- destinationDirectory = os .path .join (destination , extension )
34
+ destinationDirectory = os .path .join (destination , extension )
35
35
36
- if not os .path .exists (destinationDirectory ):
37
- os .mkdir (destinationDirectory )
36
+ if not os .path .exists (destinationDirectory ):
37
+ os .mkdir (destinationDirectory )
38
38
39
- fileName = str (fileCounter ) + "." + extension .lower ()
40
- destinationFile = os .path .join (destinationDirectory , fileName )
41
- if not os .path .exists (destinationFile ):
42
- shutil .copy (sourcePath , destinationFile )
39
+ fileName = str (fileCounter ) + "." + extension .lower ()
40
+ destinationFile = os .path .join (destinationDirectory , fileName )
41
+ if not os .path .exists (destinationFile ):
42
+ shutil .copy (sourcePath , destinationFile )
43
43
44
44
45
45
@@ -48,20 +48,20 @@ def moveFile(file, destination):
48
48
destination = None
49
49
50
50
if (len (sys .argv ) < 3 ):
51
- print ("Enter source and destination: python sort.py source/path destination/path" )
51
+ print ("Enter source and destination: python sort.py source/path destination/path" )
52
52
else :
53
- source = sys .argv [1 ]
54
- print ("Source directory: " + source )
55
- destination = sys .argv [2 ]
56
- print ("Destination directory: " + destination )
53
+ source = sys .argv [1 ]
54
+ print ("Source directory: " + source )
55
+ destination = sys .argv [2 ]
56
+ print ("Destination directory: " + destination )
57
57
58
58
if (len (sys .argv ) > 3 ):
59
- maxNumberOfFilesPerFolder = int (sys .argv [3 ])
59
+ maxNumberOfFilesPerFolder = int (sys .argv [3 ])
60
60
61
61
while ((source is None ) or (not os .path .exists (source ))):
62
- source = input ('Enter a valid source directory\n ' )
62
+ source = input ('Enter a valid source directory\n ' )
63
63
while ((destination is None ) or (not os .path .exists (destination ))):
64
- destination = input ('Enter a valid destination directory\n ' )
64
+ destination = input ('Enter a valid destination directory\n ' )
65
65
66
66
fileNumber = getNumberOfFilesInFolderRecursively (source )
67
67
onePercentFiles = int (fileNumber / 100 )
@@ -72,23 +72,23 @@ def moveFile(file, destination):
72
72
fileCounter = 0
73
73
for root , dirs , files in os .walk (source , topdown = False ):
74
74
75
- for file in files :
76
- extension = os .path .splitext (file )[1 ][1 :].upper ()
77
- sourcePath = os .path .join (root , file )
75
+ for file in files :
76
+ extension = os .path .splitext (file )[1 ][1 :].upper ()
77
+ sourcePath = os .path .join (root , file )
78
78
79
- destinationDirectory = os .path .join (destination , extension )
79
+ destinationDirectory = os .path .join (destination , extension )
80
80
81
- if not os .path .exists (destinationDirectory ):
82
- os .mkdir (destinationDirectory )
81
+ if not os .path .exists (destinationDirectory ):
82
+ os .mkdir (destinationDirectory )
83
83
84
- fileName = str (fileCounter ) + "." + extension .lower ()
85
- destinationFile = os .path .join (destinationDirectory , fileName )
86
- if not os .path .exists (destinationFile ):
87
- shutil .copy2 (sourcePath , destinationFile )
84
+ fileName = str (fileCounter ) + "." + extension .lower ()
85
+ destinationFile = os .path .join (destinationDirectory , fileName )
86
+ if not os .path .exists (destinationFile ):
87
+ shutil .copy2 (sourcePath , destinationFile )
88
88
89
- fileCounter += 1
90
- if ((fileCounter % onePercentFiles ) is 0 ):
91
- log (str (fileCounter ) + " / " + totalAmountToCopy + " processed." )
89
+ fileCounter += 1
90
+ if ((fileCounter % onePercentFiles ) is 0 ):
91
+ log (str (fileCounter ) + " / " + totalAmountToCopy + " processed." )
92
92
93
93
log ("start special file treatment" )
94
94
jpgSorter .postprocessImages (os .path .join (destination , "JPG" ), False )
0 commit comments