Last active
July 16, 2024 19:35
-
-
Save wzjoriv/961fcef1b5c3f733c0742afeb8bb7abf to your computer and use it in GitHub Desktop.
Organize blackboard submission attempts into folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
""" | |
Author: Josue N Rivera | |
Date: 1/31/2020 | |
Description: Script to organize blackboard assignment submission attempts into folders after download | |
To run: Move script to folder with attempts, then type in terminal ``python organize.py`` | |
Project Link: https://github.com/wzjoriv/wzjoriv/tree/master/scripts/blackboard | |
""" | |
files = [f for f in os.listdir() if os.path.isfile(f)] # get all files | |
try: | |
files.remove(os.path.basename(__file__)) # remove this script from the possible files | |
except Exception as e: | |
raise e | |
exit() | |
for file in files: | |
try: | |
end_std_name = file.index('_attempt') | |
start_std_name = file[:end_std_name].rindex("_") + 1 | |
except Exception as e: # if file doesn't fit pattern skip | |
print(" + " + file + " doesn't fit the pattern") | |
continue | |
hw = file[:start_std_name - 1] # get homework name | |
student = file[start_std_name:end_std_name] # get student name | |
os.renames(file, os.path.join(hw, student, file)) # move file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment