本帖最后由 jackz007 于 2022-7-12 23:28 编辑
假如要寻找的文件名是 'notepad.exe'import os
for root , dirs , files in os . walk('C:\\'):
for file in files:
if file . lower() == 'notepad.exe':
print(root)
打印出来的路径中都有要找的文件:'notepad.exe'
运行实况:Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> for root , dirs , files in os . walk('C:\\'):
for file in files:
if file . lower() == 'notepad.exe':
print(root)
C:\WINDOWS
C:\WINDOWS\system32
C:\WINDOWS\system32\dllcache
>>>
|