Created
November 24, 2019 04:42
-
-
Save koverholt/b35728f81251e46cbb12edfab259102e to your computer and use it in GitHub Desktop.
Remove repeated dates after "--" strings in Markdown filenames
This file contains hidden or 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 | |
def find_second(string, substring): | |
return string.find(substring, string.find(substring) + 1) | |
for root, dirs, files in os.walk("."): | |
for file in files: | |
if file.endswith(".md"): | |
old_path = os.path.join(root, file) | |
second_location = find_second(file, "--") | |
if second_location != -1: | |
file = file[:second_location-1] + ".md" | |
new_path = os.path.join(root, file) | |
os.rename(old_path, new_path) | |
print(new_path) | |
else: | |
print(old_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment