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



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM