-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_for_gradescope.py
executable file
·45 lines (39 loc) · 1.46 KB
/
move_for_gradescope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
import os
import re
import sys
import time
import json
topdir = 'Copybooks'
outputdir = 'GradeScopeUploads'
try:
os.mkdir(outputdir)
except FileExistsError as mkdirex:
print('Directory {dd} already exists.'.format(dd=outputdir))
for dir1name in os.listdir(topdir):
d1 = os.path.join(topdir, dir1name)
if os.path.isdir(d1):
for dir2name in os.listdir(d1):
d2 = os.path.join(d1, dir2name)
if os.path.isdir(d2):
for fname in os.listdir(d2):
if fname == 'Color.pdf':
oldname = os.path.join(d2, fname)
if os.path.isfile(oldname):
print(oldname)
newfname = '{id}-{examcode}.pdf'.format(id=dir1name, examcode=dir2name)
newname = os.path.join(outputdir,newfname)
try:
os.rename(oldname, newname)
except:
print('Error doing rename from {oldname} to {newname}'.format(oldname=oldname,newname=newname))
if not os.listdir(d2):
try:
os.rmdir(d2)
except:
print('Error doing rmdir to {d2}'.format(d2=d2))
if not os.listdir(d1):
try:
os.rmdir(d1)
except:
print('Error doing rmdir to {d1}'.format(d1=d1))