Tokyo Tech lectures will be held seven times. Therefore, in order to organize the files neatly before the lecture starts, files are created for each subject, and empty directories from the 1st to the 7th are created in it. I used to create an empty file by hand, but it was a bit annoying, so I wrote this script. It was so simple that even I, a novice programmer, took less than an hour to finish writing, but I decided to post this article because I want to be able to see how much progress I have made in the future.
main.py
"""
Creating folders from Part 1 to Part 7
"""
import os
import make_folders
QUARTER = input("What is QUARTER?-1 2 3 4-")
TOP = fr"C:\Users\Kenta Kubota\OneDrive\document\{QUARTER}Q"
def main():
make_folders.make_new_quarter_folder(TOP)
make_folders.make_new_lecture_folder(TOP)
if __name__ =="__main__":
main()
make_folders.py
import os
def make_new_quarter_folder(top):
def make_new_lecture_name_folder():
lecture_folders = input("Please write the subject of the class with a full-width space as shown below.\n\
Automotive engineering applied numerical calculation method etc.").split(" ")
if not lecture_folders == []:
for lecture_folder in lecture_folders:
new_folder = top + "\\" + lecture_folder
os.mkdir(new_folder)
if not os.path.exists(top):
os.mkdir(top)
make_new_lecture_name_folder()
elif os.listdir(top) == []:
make_new_lecture_name_folder()
def make_new_lecture_folder(top):
for root, dirs, files in os.walk(top):
if root[:37] == r"C:\Users\Kenta Kubota\OneDrive\document":
print(root)
if dirs == [] and root != top:
print('No directory')
for i in range(1, 8):
print(root, "Make a directory")
new_folder = root + "\\" + f"No.{i}Times"
os.mkdir(new_folder)
--Manipulating files with python --If you want to put r (row) and f (format) before the string at the same time, either rf or fr can be used.
--EOL appears when there is \ at the end such as r "〇〇 ".
I have written an automatic login script for Tokyo Tech Wi-Fi and Tokyo Tech portal before. At that time, I gained knowledge of web scraping. This time, I gained knowledge and experience of completely different file operations. These experiences show that it is much more efficient than just reading a book and learning the knowledge. I want to be able to write more and more scripts so that I can surprise people in a year or two.
Recommended Posts