My error
---------------------------------------------------------------------------
NotADirectoryError Traceback (most recent call last)
<ipython-input-2-b4da6c1da6e1> in <module>
12 lst = []
13 for d in lst1:
---> 14 lst = lst + listdir(d)
15 lst
<ipython-input-2-b4da6c1da6e1> in listdir(path)
4 def listdir(path): #传入存储的list
5 lst = []
----> 6 for file in os.listdir(path):
7 file_path = os.path.join(path, file)
8 lst.append(file_path)
NotADirectoryError: [Errno 20] Not a directory: '/Users/zhangzhenzhi/Desktop/Term2_Final/CASA0006/CityofLondonCrimeData/.DS_Store'
And my code is
# -*- coding: utf-8 -*-
import os
def listdir(path): #传入存储的list
lst = []
for file in os.listdir(path):
file_path = os.path.join(path, file)
lst.append(file_path)
return lst
lst1 = listdir(r'/Users/zhangzhenzhi/Desktop/Term2_Final/CASA0006/CityofLondonCrimeData' )
lst = []
for d in lst1:
lst = lst + listdir(d)
lst
I want to save all of the files' path to a listm, but I run it, it showed an error and i can't understand what can I do?