66VERSION = '1.0.5'
77
88
9- def get_foldername ( folder_names ):
9+ def get_dir_name ( dir_names ):
1010 """
11- This function searches for the foldername which appears the most
11+ This function searches for the directory name which appears the most
1212 in a given folder.
13- :param folder_names : string list
14- :return: foldername
13+ :param dir_names : string list
14+ :return: dir_name: string
1515 """
1616 match_list_len = []
17- # check if there are existing folders
18- if len (folder_names ) == 0 :
17+ # check if there are existing directories
18+ if len (dir_names ) == 0 :
1919 print ("No folder(s) found." )
2020 exit ()
21- # go through all the folder names
22- for pattern in folder_names :
23- # finding all redundant folder names
24- match_list = re .findall (pattern , str (folder_names ))
21+ # go through all the directory names
22+ for pattern in dir_names :
23+ # finding all redundant directory names
24+ match_list = re .findall (pattern , str (dir_names ))
2525 # appending there frequency to a list
2626 match_list_len .append (len (match_list ))
2727 # get the folder with the highest occurrence
2828 max_occurrence = [i for i , j in enumerate (match_list_len ) if j == max (match_list_len )][0 ]
2929 # look up how the folder name is called
30- foldername = folder_names [max_occurrence ]
30+ dir_name = dir_names [max_occurrence ]
3131 # return the folder name
32- return foldername
32+ return dir_name
3333
3434
3535def help_text ():
@@ -84,25 +84,25 @@ def main():
8484 try :
8585 # get the folder name and the number separate
8686 numbers .append (int (element_list [- 1 ]))
87- # putting the foldername back together
87+ # putting the directory name back together
8888 folder_name_str = ''
8989 for x in element_list [:- 1 ]:
9090 folder_name_str += '_' + x
9191 # remove additional underscores if they occur
9292 if folder_name_str [0 ] == '_' :
9393 folder_name_str = folder_name_str [1 :]
94- # append foldername to list
94+ # append directory name to list
9595 folder_names .append (folder_name_str )
9696 # get the digit count of the number -> this part fails pretty easily
9797 numbers_num_digits .append (int (len (element_list [- 1 ])))
9898 except ValueError :
9999 print (f"Was not able to convert string to int of folder '{ element } '" )
100100 continue
101101 # name of the new folder
102- foldername = ""
102+ directory_name = ""
103103 # if no additional argument was given
104104 if command_line_args .__len__ () == 1 or command_line_args [1 ] == '' :
105- foldername = get_foldername (folder_names )
105+ directory_name = get_dir_name (folder_names )
106106 # if a additional command line argument is given
107107 elif command_line_args .__len__ () == 2 and command_line_args [1 ] != '' :
108108 # help flag is set
@@ -119,28 +119,28 @@ def main():
119119 print ('CDIR Version {}\n ' .format (VERSION ))
120120 exit (0 )
121121 elif command_line_args [1 ].isdigit ():
122- foldername = get_foldername (folder_names )
122+ directory_name = get_dir_name (folder_names )
123123 num_new_dirs = int (command_line_args [1 ])
124124 else :
125- # given argument is a foldername
126- foldername = command_line_args [1 ]
125+ # given argument is a directory name
126+ directory_name = command_line_args [1 ]
127127 # if a directory name and number of directories is given
128128 elif command_line_args .__len__ () == 3 :
129129 if command_line_args [1 ][0 ] == '-' or not command_line_args [2 ].isdigit ():
130130 raise SyntaxError ("Command not properly used!" )
131- # given argument is a foldername
132- foldername = command_line_args [1 ]
131+ # given argument is a directory name
132+ directory_name = command_line_args [1 ]
133133 num_new_dirs = int (command_line_args [2 ])
134134 else :
135135 # something went wrong
136136 raise SyntaxError ("Command not properly used!" )
137- # highest number of chosen foldername
137+ # highest number of chosen directory name
138138 highest_number = - 1
139139 # length of the number (needed for given 0s before the number)
140140 number_length = - 1
141- # get the highest number of the folder names
141+ # get the highest number of the directory numbering
142142 for i , element in enumerate (folder_names ):
143- if element == foldername and highest_number < numbers [i ]:
143+ if element == directory_name and highest_number < numbers [i ]:
144144 highest_number = numbers [i ]
145145 number_length = numbers_num_digits [i ]
146146 # set the new number
@@ -157,11 +157,11 @@ def main():
157157 # update the placeholder counter
158158 if new_number_digit_count > highest_number_digit_count and placeholder_count > 0 :
159159 placeholder_count -= 1
160- # create the new folder name
161- new_foldername = foldername + '_' + ('0' * placeholder_count ) + str (new_number )
162- print (f"Creating directory { new_foldername } " )
163- # create the new folder
164- os .makedirs (new_foldername )
160+ # put the directory name together
161+ new_dir_name = directory_name + '_' + ('0' * placeholder_count ) + str (new_number )
162+ print (f"Creating directory { new_dir_name } " )
163+ # create the new directory
164+ os .makedirs (new_dir_name )
165165 # everything went fine -> print and terminate
166166 print ("done." )
167167
0 commit comments