f=open("D://111.cc",mode="w",encoding="UTF-8")
f.close()
import os
os.remove("D://222.ccc123")
os.close()
os.mkdir("E://bb")
os.makedirs("D:\\a\\b")
os.removedirs(path) os.remove()
import os
import shutil
#第一个参数是源文件,第二个拷贝文件
shutil.copyfile("D://111.CC","D://222.ccc")
os.rename("D://222.ccc","D://222.ccc123")
os.stat("D://abc.txt").st_size
def countDirs(dp):
tt=tuple(os.walk(dp))
print("文件夹"+dp+"的信息:")
print("文件夹的个数: ",len(tt[0][1]),"文件的个数: ",len(tt[0][2]))
d1="D:\\tomcat7\\bin"
countDirs(d1)
文件夹D:\tomcat7\bin的信息: 文件夹的个数: 0 文件的个数: 28 Process finished with exit code 0
def showAllDirs(dp):
tt=os.walk(dp);
for l in tt:
for lf in l[1]:
print("目录的路径是:",l[0]+"\\"+lf)
def showAllDirsFiles(dirPath):
tt=os.walk(dirPath);
for l in tt:
for ll in l[2]:
print("文件的路径是:",l[0]+"\\"+ll)
def readFile():
f=open(r"D:///bbb.txt",encoding="UTF-8")
for line in f:
#去除多余的换行符
print(line.strip())
f.close();
def readFile1():
f=open(r"D:///bbb.txt",encoding="UTF-8")
while 1:
#print("j")
lines=f.readlines(10000);
if not lines:
#print("end")
break;
for line in lines:
print(line.strip())
f.close()
def writeFile():
a=list();
a.append("a你好")
a.append("b哈喽")
a.append("c")
#a追加模式w覆盖模式
f=open("D://pp.txt",mode='a',encoding="UTF-8")
print("文件大小:",f)
for c in a:
f.write(c+"\n")
f.close()
print("写入成功!")
#拷贝整个目录到另一个路径下
shutil.copytree("E:\\11111111111\\a","E:\\11111111111\\b");
#剪切整个目录到另一个路径下
shutil.move("E:\\11111111111\\a","E:\\11111111111\\cc")
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有