Error while using listdir in Python

后端 未结 8 940
小蘑菇
小蘑菇 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 05:06

    You want:

    print len([name for name in os.listdir('./client_side/') if os.path.isfile(name)])
    

    with a "." before "/client_side/".

    The dot means the current path where you are working (i.e. from where you are calling your code), so "./client_side/" represents the path you want, which is specified relatively to your current directory.

    If you write only "/client_side/", in unix, the program would look for a folder in the root of the system, instead of the folder that you want.

提交回复
热议问题