-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom file rename chronology indexed
- Loading branch information
1 parent
f4a05af
commit 01a298b
Showing
3 changed files
with
35 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import Config | ||
|
||
class RenameFiles: | ||
""" Rename output files """ | ||
|
||
@staticmethod | ||
def rename(exam_name: str): | ||
""" public static """ | ||
exam_files = list(os.listdir("out")) | ||
|
||
def name_filter(name: str): | ||
return Config.EXAM_NAME not in name and os.path.isfile(f"out/{name}") | ||
|
||
def sort_key(name: str): | ||
return int(name.replace("exam-", "").replace(".txt", "")) | ||
|
||
num_of_files_in_dir = len(exam_files) | ||
exam_files = list(filter(name_filter, exam_files)) | ||
file_num = num_of_files_in_dir - len(exam_files) + 1 | ||
exam_files.sort(key = sort_key, reverse=True) | ||
|
||
for exam_file in exam_files: | ||
os.rename(f"out/{exam_file}", f"out/{exam_name}-{file_num}.txt") | ||
file_num += 1 | ||
|
||
if __name__ == "__main__": | ||
RenameFiles.rename(Config.EXAM_NAME) |
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