【发布时间】:2020-10-14 10:28:45
【问题描述】:
import os
import shutil
FileCount = 0
filelist = []
ext = str(input())
for foldername, subfolders, filenames in os.walk('F:\\'):
for filename in filenames:
if filename.endswith(ext):
txtFileCount+=1;
filelist.append(filename)
print(os.path.abspath(filename))
print(txtFileCount)
print(filelist)
输出: 文件位于“G”目录,而选择的目录为“F”。
G:\Pillow\filecheckerProject\free_cam_8_7_0.msi
G:\Pillow\filecheckerProject\BlueJ-windows-421.msi
G:\Pillow\filecheckerProject\free_cam_8_7_0.msi
G:\Pillow\filecheckerProject\mysql-installer-web-community-8.0.17.0.msi
G:\Pillow\filecheckerProject\PowerToysSetup.msi
5
['free_cam_8_7_0.msi', 'BlueJ-windows-421.msi', 'free_cam_8_7_0.msi', 'mysql-installer-web-community-8.0.17.0.msi', 'PowerToysSetup.msi']
【问题讨论】:
-
请正确格式化您的代码,click here to learn how。
-
请澄清您的问题,也正如@БогданОпир 所说,正确格式化您的代码,以便更容易理解。
-
你忽略了
os.walk给你的foldername。
标签: python-3.x operating-system shutil