DouDou commited on
Upload data1/rename2.py with huggingface_hub
Browse files- data1/rename2.py +17 -0
data1/rename2.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import glob
|
| 3 |
+
|
| 4 |
+
# get all target csv files
|
| 5 |
+
file_list = glob.glob("./datasets/all/chempile_code_complete_*.csv")
|
| 6 |
+
|
| 7 |
+
for file_path in file_list:
|
| 8 |
+
# extract filename and number part
|
| 9 |
+
dir_name, file_name = os.path.split(file_path)
|
| 10 |
+
prefix, num_suffix = file_name.split("_")[-2], file_name.split("_")[-1].split(".")[0]
|
| 11 |
+
# convert number to 3-digit format
|
| 12 |
+
new_num = num_suffix.zfill(3)
|
| 13 |
+
# construct new file path
|
| 14 |
+
new_file_name = file_name.replace(f"{prefix}_{num_suffix}", f"{prefix}_{new_num}")
|
| 15 |
+
new_file_path = os.path.join(dir_name, new_file_name)
|
| 16 |
+
# rename file
|
| 17 |
+
os.rename(file_path, new_file_path)
|