Skip to content

Instantly share code, notes, and snippets.

@koverholt
Created November 24, 2019 04:42
Show Gist options
  • Save koverholt/b35728f81251e46cbb12edfab259102e to your computer and use it in GitHub Desktop.
Save koverholt/b35728f81251e46cbb12edfab259102e to your computer and use it in GitHub Desktop.
Remove repeated dates after "--" strings in Markdown filenames
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