0
这里是我的代码和错误!请给我一个提示如何递归地打印每个文件或文件夹的路径名称
import os
def traverse(path, d):
for item in os.listdir(path):
item = os.path.join(path, d)
try:
traverse(path,d)
except:
print (path)
我的错误:
traverse ("test",0)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
traverse ("test",0)
File "C:\Users\Phuchu\Desktop\Python\homework8.py", line 65, in traverse
for item in os.listdir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'test\\*.*'
什么是你的当前目录? 'test'是那个子目录吗? – 2013-03-15 18:54:53
你不应该用'*。*''作为'd' – thkang 2013-03-15 19:07:39
是的参数来调用你的函数。而且测试中还有一些文件夹 – user2011873 2013-03-15 19:08:37