|
import os |
|
import shutil |
|
|
|
|
|
years = ["2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024"] |
|
base_dir = '/media/joe/512-3/csv' |
|
|
|
|
|
for year in years: |
|
folder_path = os.path.join(base_dir, f"CC-MAIN-{year}") |
|
if not os.path.exists(folder_path): |
|
os.makedirs(folder_path) |
|
print(f"Created folder: {folder_path}") |
|
|
|
|
|
for year in years: |
|
year_folder = os.path.join(base_dir, f"CC-MAIN-{year}") |
|
|
|
year_files = [f for f in os.listdir(base_dir) if f.startswith(f"forti-sampled_dataset_CC-MAIN-{year}")] |
|
|
|
total_files = len(year_files) |
|
if total_files == 0: |
|
print(f"No files found for the year {year}") |
|
continue |
|
|
|
|
|
for index, file_name in enumerate(sorted(year_files)): |
|
new_file_name = f"train-{str(index+1).zfill(5)}-of-{str(total_files).zfill(4)}.csv" |
|
|
|
old_file_path = os.path.join(base_dir, file_name) |
|
new_file_path = os.path.join(year_folder, new_file_name) |
|
|
|
|
|
try: |
|
shutil.move(old_file_path, new_file_path) |
|
print(f"Moved and renamed: {old_file_path} to {new_file_path}") |
|
except Exception as e: |
|
print(f"Error moving file {old_file_path}: {e}") |
|
|
|
|