Untitled
unknown
plain_text
2 years ago
1.1 kB
1
Indexable
def create_subject_directory(path): # Check if the directory is empty if not os.listdir(path): # If it's empty, create "subject1" os.mkdir(os.path.join(path, "subject1")) print("Created directory: " + os.path.join(path, "subject1")) else: # If it's not empty, find the next available subject number existing_subjects = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))] highest_subject_number = 0 for subject in existing_subjects: if subject.startswith("subject"): try: subject_number = int(subject[len("subject"):]) if subject_number > highest_subject_number: highest_subject_number = subject_number except ValueError: pass next_subject_number = highest_subject_number + 1 next_subject_name = "subject" + str(next_subject_number) os.mkdir(os.path.join(path, next_subject_name)) print("Created directory: " + os.path.join(path, next_subject_name))
Editor is loading...