Discuss / Python / 总结

总结

Topic source

浅言87780

#1 Created at ... [Delete] [Delete and Lock User]

import os

#输出当前目录下的所有.py文件

[x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1]=='.py']

#输出当前目录下的所有目录文件

[x for x in os.listdir('.') if os.path.isdir(x)]

#查看当前目录绝对路径

os.path.abspath('.')

#创建新目录

os.path.join('F:\\pythonwork\\fundation','tdir')

os.mkdir('F:\\pythonwork\\fundation\\tdir')

#删掉目录

os.rmdir('F:\\pythonwork\\fundation\\tdir')

#重命名

os.rename('text.txt','test.py')

#删掉文件

os.remove('test.py')


  • 1

Reply