Skip to content

Commit

Permalink
Fixed the lack of indexation of files.
Browse files Browse the repository at this point in the history
Added comments.
  • Loading branch information
lcgeneralprojects committed Jul 12, 2023
1 parent 22c759a commit 37f361b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions main.py
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)

0 comments on commit 37f361b

Please sign in to comment.