获取文件下的所有py文件
import os.path
path=os.getcwd()
l1=os.listdir(path)
for filename in l1:
if filename.endswith('.py'):
print(filename)
遍历文件夹中的所有文件
import os
path=os.getcwd()
l1=os.walk(path)
for dirpath,dirname,filename in l1:
print(dirpath)
print(dirname)
print(filename)
for file in filename:
print(os.path.join(dirpath,file))
#文件复制,不需要手动复制with open('test.txt','rb') as file: with open('test1.txt','wb') as target_file: target_file.write(file.read())#os模块是操作系统相关的一个模块import osos.system('notepad.exe') #调用Notepados.startfile(r'D:\exe\PotPlayerSetup64.exe') #调用可