print("\n","="*10,"蚂蚁庄园动态","="*10)
file = open('massage','w')
print("\n即将显示……")

 

 

print("\n","="*10,"蚂蚁庄园动态","="*10)
file = open('massage.txt','w')
file.write("你使用了1张加速卡,小鸡撸起袖子开始双手吃饲料。")
print("\n写入了一条动态……")
file.close()

 

 

print("\n","="*25,"蚂蚁庄园动态","="*25,"\n")
with open('massage.txt','r') as file:
massage = file.read()
print(massage)
print("\n","="*29,"over","="*29,"\n")

 

 

print("\n","="*25,"蚂蚁庄园动态","="*25,"\n")
with open('massage.txt','r') as file:
number = 0
while True:
number += 1
line = file.readline()
if line == '':
break
print(number,line,end= '\n')
print("\n","="*25,"over","="*25,"\n")

 

 

import os
path = "C:\\demo"
print("【",path,"】 目录下包括的文件和目录:")
for root, dirs, files in os.walk(path, topdown = True):
for name in dirs:
print("❤",os.path.join(root,name))
for name in files:
print("1",os.path.join(root,name))

 

 

import os
fileinfo = os.stat("C:\\demp")
print("文件完整路径:",os.path.abspath("C:\\demp"))
print("索引号:",fileinfo.st_ino)
print("设备名:",fileinfo.st_dev)
print("文件大小:",fileinfo.st_size,"字节")
print("最后一次访问时间:",fileinfo.st_atime)
print("最后一次修改时间:",fileinfo.st_mtime)
print("最后一次状态变化时间:",fileinfo.st_ctime)

 

 

import os
import time
path = str(input("请输入需要生成的文件数:"))
path = int(path)
def formatTime():
return time.strftime('%Y%m%d%H%M%S',time.localtime())
time = formatTime()
time = str(time)
file = open(time+'.txt','w')
print("file" +"1:"+time)
time = int(time)+1
time = str(time)
file = open(time+'.txt','w')
print("file"+"2:"+time)

 

 

import os
path = "C:\\test"
number = int(input("请输入需要生成的文件夹个数:"))
for i in range(number):
ml = str(i+1)
os.makedirs(path + "\\" + ml)
print("文件夹 " + ml + " 创建成功!")

 

posted on 2022-11-10 17:11  tangjia俊  阅读(24)  评论(0)    收藏  举报