-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the lack of indexation of files.
Added comments.
- Loading branch information
1 parent
22c759a
commit 37f361b
Showing
1 changed file
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
# This is a project for an automated file renamer | ||
# TODO: allow for the user to input the arguments using a console | ||
# TODO: implement GUI | ||
# TODO: make the empty-prefixed calls identity operations for those base directories | ||
|
||
import os | ||
|
||
|
||
def renamer(prefix, base_dir): | ||
for directory in os.listdir(base_dir): | ||
if os.path.isdir(directory): | ||
new_dir_name = prefix + '_' + directory | ||
os.rename(directory, new_dir_name) | ||
for file in os.listdir(directory): | ||
new_file_name = directory + '/' + prefix + '_' + file | ||
os.rename(directory + '/' + file, new_file_name) | ||
if os.path.isdir(base_dir + '/' + directory): | ||
for file in os.listdir(base_dir + '/' + directory): | ||
if prefix != '': | ||
new_file_name = base_dir + '/' + directory + '/' + prefix + '_' + file | ||
os.rename(base_dir + '/' + directory + '/' + file, new_file_name) # Adding a prefix | ||
# TODO: probably worth it to find a good way to get rid of this 'if' block | ||
if file[3].isalpha(): # Adding a corresponding number to the files with solutions | ||
tmp = '' | ||
for char in directory: | ||
if char.isdigit(): | ||
tmp += char | ||
if tmp != '': | ||
tmp += '_' | ||
new_name = file[:3] + tmp + file[3:] # The 'cutting' point should not be at index 3, but after | ||
# the prefix | ||
os.rename(base_dir + '/' + directory + '/' + file, base_dir + '/' + directory + '/' + new_name) | ||
new_dir_name = base_dir + '/' + prefix + '_' + directory | ||
os.rename(base_dir + '/' + directory, new_dir_name) | ||
|
||
|
||
if __name__ == '__main__': | ||
pass | ||
prefix = input("Prefix: ") | ||
base_dir = input("Base directory: ") | ||
renamer(prefix, base_dir) |