Error while using listdir in Python

后端 未结 8 936
小蘑菇
小蘑菇 2020-12-10 04:14

I\'m trying to get the list of files in a particular directory and count the number of files in the directory. I always get the following error:

WindowsError         


        
8条回答
  •  情书的邮戳
    2020-12-10 04:54

    I decided to change the code into:

    def numOfFiles(path):
        return len(next(os.walk(path))[2])
    

    and use the following the call the code:

    print numOfFiles("client_side")
    

    Many thanks to everyone who told me how to pass the windows directory correctly in Python and to nrao91 in here for providing the function code.

    EDIT: Thank you eryksun for correcting my code!

提交回复
热议问题