import os
# 创建多级文件(不含文件)
def create_dir(file_path):
if os.path.exists(file_path) is False:
os.makedirs(file_path)
if __name__ == '__main__':
# 创建绝对路径文件(硬盘)
create_dir('D:/aaa')
with open('D:/aaa/a.txt', 'w', encoding='utf-8') as f:
f.write('七夕节')
# 创建相对路径文件(项目根目录)
with open('a.txt', 'w', encoding='utf-8') as f:
f.write('七夕节')
python 创建多级文件夹、创建文件
最新推荐文章于 2024-03-07 11:02:41 发布