<pre>
with os.scandir('..') as it:
for entry in it:
print(entry.name.encode('utf-8'))
</pre>
第二题
<pre>
import os
def searchFile(path,filename):
with os.scandir(path) as it:
for entry in it:
if entry.is_file() and filename in entry.name :
print(entry.path.encode('utf-8'))
elif entry.is_dir():
searchFile(entry.path,filename)
searchFile('/Downloads','py')
</pre>
用户5254891376
第一题
<pre> with os.scandir('..') as it: for entry in it: print(entry.name.encode('utf-8')) </pre> 第二题 <pre> import os def searchFile(path,filename): with os.scandir(path) as it: for entry in it: if entry.is_file() and filename in entry.name : print(entry.path.encode('utf-8')) elif entry.is_dir(): searchFile(entry.path,filename) searchFile('/Downloads','py') </pre>