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