-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment_folder.py
More file actions
34 lines (32 loc) · 1.26 KB
/
assignment_folder.py
File metadata and controls
34 lines (32 loc) · 1.26 KB
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
import os
class AssignmentFolder:
"""
A class to represent the folder of assignments, containing the necessary methods
to pull filenames and organize the directory.
"""
def __init__(self, directory):
"""
A constructor that takes in a String representing the directory
of the assignment folder.
"""
self.directory = directory
self.assignments = self.get_assignments()
def get_assignments(self):
"""
A method that returns an array of all file paths from the provided
directory. Utilizes the os library, creating a shell to the cmd of
the system.
"""
all_files = []
os_directory = os.fsencode(self.directory)
# encodes the filename into a usable object
for file in os.listdir(os_directory):
# decodes the file into string format for future use
filename = os.fsdecode(file)
# checks if the current file is a valid .py script
if filename.endswith(".py"):
# creates a full string of the directory and filename combined
# for future use
filepath = os.path.join(self.directory, filename)
all_files.append(filepath)
return all_files