【python】小脚本-列出当前目录下所有的文件及子目录中的文件
上代码:
import os
import sys
file_names = []
for root, dirs, files in os.walk(os.path.dirname(os.path.abspath(__file__))):
for file in files:
# name = os.path.join(root, file).split("\\")[-1].replace("-", "==").replace(".tar.gz", "").replace(".tar", "")
name = os.path.join(root, file)
print(name)
file_names.append(name)
#print(file_names)
input("Press <enter>")
运行结果:
简单到ctrl+c ,ctrl+v,就行……