Skip to content

Instantly share code, notes, and snippets.

@encima
Created November 15, 2016 09:53
Show Gist options
  • Save encima/67328215e7cf505a57e2882adbc94129 to your computer and use it in GitHub Desktop.
Save encima/67328215e7cf505a57e2882adbc94129 to your computer and use it in GitHub Desktop.
Unpack Student Projects from a Teaching Solution to Sub Folders for Each Student
import os
import sys
import time
import shutil
import subprocess
# ENSURE YOUR FEEDBACK FILE IS IN THE PATH SUPPLIED
path = sys.argv[1] #full path should go here
module_code = sys.argv[2]
dir_contents = os.listdir(path)
for content in dir_contents:
full_path = os.path.join(path, content)
print(full_path)
if not os.path.isdir(full_path) and not content.startswith('.') and content.startswith(module_code):
student_path = content[0:62] #compare initial attempts
student_files = [x for x in dir_contents if student_path in x and not x.startswith('.')] #find all similar files
print(student_files)
student_folder = os.path.join(path, "folder_{}".format(student_path))
try:
print("Creating {}".format(student_folder))
os.makedirs(student_folder, exist_ok=True) #make folder and move contents of student work in
shutil.copyfile(os.path.join(path, "feedback.md"), os.path.join(student_folder, "feedback.md"))
for original in student_files:
print("Moving {} to {}".format(original, student_folder))
shutil.move(os.path.join(path, original), os.path.join(student_folder, original)) #os rename fails for directories
except OSError as e:
print(e)
print("folder exists or permissions need fixing")
print("---------")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment