-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-file-ext.py
25 lines (20 loc) · 992 Bytes
/
add-file-ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pathlib import Path
import re
# Define the pattern you want to match
# match filenames containing string: pattern = re.compile(r'data')
# match filenames starting with string: pattern = re.compile(r'^report')
# match filenames ending with string: pattern = re.compile(r'_2023$')
# Define the pattern you want to match
pattern = re.compile(r"^business") # Replace 'your_pattern_here' with your actual pattern
) # Replace 'your_pattern_here' with your actual pattern
# Get the current directory
# current_directory = os.getcwd()
# Set directory
directory = Path(r"C:\Users\mahmad\OneDrive - Ryan RTS\Downloads\checks")
# Loop through the files in the directory
for file in directory.iterdir():
if file.is_file() and pattern.search(file.name) and not file.name.endswith('.csv'):
new_filename = file.name + '.csv'
new_path = file.with_name(new_filename)
file.rename(new_path)
print(f'Renamed: {file.name} to {new_filename}')