批量产生文件夹(Python)

1、指定文件夹路径,在该路径下批量生成指定名称(具有一定的规律性)的文件夹

# 导入OS库
import os
FilePath = "" # 指定文件夹路径
NumSets = # 文件夹个数
def BatProFile_function(FilePath,NumSets):
    os.chdir(FilePath) # 定位
    for i in range(NumSets):
        IsExist = os.path.exists("S" + str(i+1)) # 这里每个文件夹的名称为S1,S2……
            if not IsExist:
                os.makedirs("S" + str(i+1))
                #print("文件夹创建成功")
            else:
                #print("文件夹已存在")
                continue
    

 

关于OS库的使用:

待更新……

 

posted @ 2022-08-17 11:36  霸喯啵儿  阅读(305)  评论(0)    收藏  举报