I wrote an empty directory automatic creation script in Python

Reason

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.

Library used

code

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)

Knowledge gained

--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.

problem

--EOL appears when there is \ at the end such as r "〇〇 ".

Impressions I made

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

I wrote an empty directory automatic creation script in Python
I wrote python in Japanese
I wrote an automatic installation script for Arch Linux
I wrote Fizz Buzz in Python
I wrote the queue in Python
I wrote the stack in Python
I wrote a function to load a Git extension script in Python
I wrote a script to extract a web page link in Python
Pin current directory to script directory in Python
I wrote the sliding wing in creation.
I wrote an IPython Notebook-like Tkinter wrapper [Python]
A memo that I wrote a quicksort in Python
I wrote a class in Python3 and Java
I wrote "Introduction to Effect Verification" in Python
I wrote an IPython Notebook-like Gtk wrapper [Python]
I get an Import Error in Python Beautiful Soup
Quicksort an array in Python 3
Command line tool to put .gitkeep in an empty directory
Empty multidimensional array in python
Run automatic jobs in python
I got an error in vim and zsh in Python 3.7 series
[Fundamental Information Technology Engineer Examination] I wrote an algorithm for determining leap years in Python.
I wrote a script to get a popular site in Japan
[Python] Get the script execution directory with an absolute path
I understand Python in Japanese!
What I learned in Python
I wrote a script that splits the image in two
I got an AttributeError when mocking the open method in python
I wrote the code to write the code of Brainf * ck in python
I wanted to do something like an Elixir pipe in Python
Linebot creation & file sharing in Python
Write an HTTP / 2 server in Python
Get the script path in Python
Develop an investment algorithm in Python 2
I sent an SMS with Python
I wrote Gray Scale in Pytorch
I learned about processes in Python
I can't install scikit-learn in Python
AWS Layer Creation Script for python
Python in is also an operator
I tried Line notification in Python
An alternative to `pause` in Python
GUI creation in python using tkinter 2
[Fundamental Information Technology Engineer Examination] I wrote an algorithm for the maximum value of an array in Python.
I want to color a part of an Excel string in Python
[Python] I forcibly wrote a short Perlin noise generation function in Numpy.
I made a script in python to convert .md files to Scrapbox format
I wrote FizzBuzz in python using a support vector machine (library LIVSVM).
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I put Python 2.7 in Sakura VPS 1GB.
I tried to implement PLSA in Python
I tried to implement permutation in Python
I made a payroll program in Python!
Sample script to trap signals in Python
I tried to implement PLSA in Python 2
I tried sending an email with python.
I tried using Bayesian Optimization in Python
I can't debug python scripts in Eclipse
I implemented Cousera's logistic regression in Python
I tried to implement ADALINE in Python
I wanted to solve ABC159 in Python