Created
May 1, 2019 08:25
-
-
Save EmadMokhtar/677a1f72f91d9a5a0268d0fba1ec25ab to your computer and use it in GitHub Desktop.
Notion notes sanitizer
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
import os | |
current_dir = os.getcwd() | |
files_extension = ['.md', '.txt', '.docx'] | |
bad_chars = { | |
'#': 'hash', | |
'|': '', | |
'[': '', | |
']': '', | |
'?': '', | |
'&': 'and', | |
} | |
files = [f for f in os.listdir(current_dir) | |
if os.path.isfile(f) and | |
any([ext for ext in files_extension if ext in f])] | |
for file in files: | |
if any(c for c in bad_chars.keys() if c in file): | |
new_name = file | |
for k, v in bad_chars.items(): | |
new_name = new_name.replace(k, v) | |
old_file_path = os.path.join(current_dir, file) | |
new_file_path = os.path.join(current_dir, new_name) | |
os.rename(old_file_path, new_file_path) | |
print(f'Change file name from \n"{file}" name to \n"{new_name}"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to run
fix_name.py
file to the folder where the notes are located.python3 fix_name.py
.