Skip to content

Instantly share code, notes, and snippets.

@wzjoriv
Last active July 16, 2024 19:35
Show Gist options
  • Save wzjoriv/961fcef1b5c3f733c0742afeb8bb7abf to your computer and use it in GitHub Desktop.
Save wzjoriv/961fcef1b5c3f733c0742afeb8bb7abf to your computer and use it in GitHub Desktop.
Organize blackboard submission attempts into folders
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