24 lines
956 B
Python
24 lines
956 B
Python
import os
|
|
import re
|
|
# Get a list of all files in the current directory
|
|
files = []
|
|
for root, dirs, filenames in os.walk('.'):
|
|
for filename in filenames:
|
|
files.append(os.path.join(root, filename))
|
|
# Loop through each file
|
|
for file in files:
|
|
# Check if the file is a markdown file (.md)
|
|
if file.endswith('.md'):
|
|
with open(file, 'r') as f:
|
|
content = f.read()
|
|
# Find all strings that start with ]( and end with.md
|
|
matches = re.findall(r'\]\(([^)]+)\.md\)', content)
|
|
# Loop through each match
|
|
new_content = content
|
|
for match in matches:
|
|
# If the match contains at least one /, remove everything before the last /
|
|
if '/' in match:
|
|
new_match = match.split('/')[-1]
|
|
new_content = new_content.replace(match, new_match)
|
|
with open(file, 'w') as f:
|
|
f.write(new_content) |