意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

Python之文件操作

来源:恒创科技 编辑:恒创科技编辑部
2023-12-29 14:20:59

Github:​​https://github.com/huangshiyu13/PythonFileLib​​

1.获得文件夹下所有文件名


Python之文件操作

for file in os.listdir(imageDir):
file_path = os.path.join(imageDir, file)
if os.path.isfile(file_path) and os.path.splitext(file_path)[1]=='.rmvb': print file

2.判断文件夹是否存在,如果不存在则创建,如果存在则删除后创建

outDir = "outDir";
if os.path.isdir(outDir):
shutil.rmtree(outDir)
os.mkdir(outDir)

3.判断文件是否存在

import os 
os.path.isfile('test.txt') #如果不存在就返回False

4.复制文件

def copyFile(source, target):
open(target, "wb").write(open(source, "rb").read())

黄世宇/Shiyu Huang's Personal Page:​​https://huangshiyu13.github.io/​​



上一篇: django多后端发送邮件 下一篇: 关于Python列表的索引取值问题