1. 程式人生 > >Python3 批量建立資料夾

Python3 批量建立資料夾

# -*- coding: utf-8 -*-
# @Time       : 2018/12/23 8:09
# @Author     : Philly
# @File       : make_directories.py
# @Description: 批量建立資料夾
import os

path = r'C:\Users\hasee\Desktop\resources\學習\LearningNotes\MySQL\books\mysql_scripts\\'
for i in range(2, 31):
    file_name = 'chapter' + str(i)
    dir_name = path + file_name
    if file_name not in os.listdir(path):   # 資料夾名稱不存在才建立
        os.mkdir(dir_name)

# print('chapter1' in os.listdir(path))