import os
file_path = “/Users/lixiangxiang/Desktop/newDir/”
path_list = os.listdir(file_path)
print(path_list)
path_name=[]
#把文件列表写入save.txt中
def saveList(pathName):
for file_name in pathName:
# "a"表示以不覆盖的形式写入到文件中,当前文件夹如果没有"save.txt"会自动创
建
with open(“save.txt”,“a”) as f:
f.write(file_name.split(".")[0] + “\n”)
# print(file_name)
f.close()
def dirList(path_list):
for i in range(0,len(path_list)):
path=os.path.join(file_path,path_list[i])
if os.path.isdir(path):
saveList(os.listdir(path))
dirList(path_list)
saveList(path_list)