Skip to content

Commit

Permalink
Refactored file path handling and sorting logic in translate_all.py
Browse files Browse the repository at this point in the history
  • Loading branch information
artwalker committed Dec 27, 2023
1 parent 6784cd9 commit 146bc06
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions translate_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
from termcolor import colored

# Get a list of all text files in the book directory
# Linux version
file_list = glob.glob('./book/*.txt')
# Windows version
# file_list = glob.glob('.\\book\\*.txt')
file_list = glob.glob(os.path.join('.', 'book', '*.txt'))

# Sort the files by their numerical prefix
# Linux version
file_list.sort(key=lambda x: int(x.split('_')[0].split('/')[-1]))
# Windows version
# file_list.sort(key=lambda x: int(x.split('_')[0].split('\\')[-1]))
file_list.sort(key=lambda x: int(os.path.basename(x).split('_')[0]))

# Use your translation function on each file
for file in file_list:
Expand All @@ -21,4 +15,4 @@
os.system(f'python easy_translator.py {file}')

# Print a message when you're done
print(colored('All done!', 'magenta'))
print(colored('All done!', 'magenta'))

0 comments on commit 146bc06

Please sign in to comment.