|
| 1 | +""" |
| 2 | +Script Name: File_Collector.py |
| 3 | +
|
| 4 | +Author: Madhurima Rawat |
| 5 | +
|
| 6 | +Purpose: |
| 7 | + This script traverses through Week 1 to Week 12 folders inside a given source directory. |
| 8 | + It looks for an "Assignment" subfolder in each week and copies all files from it into |
| 9 | + a single destination folder. |
| 10 | +
|
| 11 | + To avoid filename conflicts, each copied file is prefixed with the week number |
| 12 | + (e.g., Week1_filename.ext). |
| 13 | +
|
| 14 | +Usage: |
| 15 | + - Set `source_base_path` to the directory containing "Week 1" to "Week 12" folders. |
| 16 | + - Set `destination_folder` to where you want to collect all assignment files. |
| 17 | + - Run the script in any Python environment with appropriate access permissions. |
| 18 | +""" |
| 19 | + |
| 20 | +import os |
| 21 | +import shutil |
| 22 | + |
| 23 | +# ✏️ Configure paths below |
| 24 | +source_base_path = r"Source Path" # Path to course directory |
| 25 | +destination_folder = r"Destination Path" # Path to save all assignments |
| 26 | + |
| 27 | +# Create the destination folder if it doesn't already exist |
| 28 | +os.makedirs(destination_folder, exist_ok=True) |
| 29 | + |
| 30 | +# 🔁 Loop through Week 1 to Week 12 |
| 31 | +for week_num in range(1, 13): |
| 32 | + # Construct full path to the Assignment folder inside each week |
| 33 | + assignment_path = os.path.join(source_base_path, f"Week {week_num}", "Assignment") |
| 34 | + |
| 35 | + # ✅ Check if Assignment folder exists |
| 36 | + if os.path.exists(assignment_path): |
| 37 | + # Loop through all files inside Assignment folder |
| 38 | + for file_name in os.listdir(assignment_path): |
| 39 | + file_path = os.path.join(assignment_path, file_name) |
| 40 | + |
| 41 | + # ✅ Copy only files (skip directories) |
| 42 | + if os.path.isfile(file_path): |
| 43 | + # Prefix filename with week number to avoid overwriting |
| 44 | + dest_file_name = f"Week{week_num}_{file_name}" |
| 45 | + dest_path = os.path.join(destination_folder, dest_file_name) |
| 46 | + |
| 47 | + # Copy file preserving metadata |
| 48 | + shutil.copy2(file_path, dest_path) |
| 49 | + |
| 50 | + print(f"✅ Copied files from Week {week_num}") |
| 51 | + else: |
| 52 | + print(f"⚠️ Assignment folder not found in Week {week_num}") |
0 commit comments