-
Notifications
You must be signed in to change notification settings - Fork 113
/
clean_and_rename_files.py
32 lines (25 loc) · 1.11 KB
/
clean_and_rename_files.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
26
27
28
29
30
31
32
import os
def remove_non_post_files(directory):
for filename in os.listdir(directory):
if not filename.startswith('post'):
file_path = os.path.join(directory, filename)
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Removed {file_path}")
def rename_files(directory):
for filename in os.listdir(directory):
if filename.startswith('post_'):
new_filename = filename[5:]
old_file_path = os.path.join(directory, filename)
new_file_path = os.path.join(directory, new_filename)
os.rename(old_file_path, new_file_path)
print(f"Renamed {old_file_path} to {new_file_path}")
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description='Clean and rename topics JSON files in a directory')
parser.add_argument('--topics_dir', type=str, default='./data/topics/',
help='Directory of topics JSON files to process')
args = parser.parse_args()
remove_non_post_files(args.topics_dir)
rename_files(args.topics_dir)