Python 2.5.2: trying to open files recursively

前端 未结 3 1159
南方客
南方客 2021-01-05 05:38

The script below should open all the files inside the folder \'pruebaba\' recursively but I get this error:

Traceback (most recent call last):
F

3条回答
  •  有刺的猬
    2021-01-05 06:33

    You're trying to open everything you see. One thing you tried to open was a directory; you need to check if an entry is a file or is a directory, and make a decision from there. (Was the error IOError: [Errno 21] Is a directory not descriptive enough?)

    If it is a directory, then you'll want to make a recursive call to your function to walk over the files in that directory as well.

    Alternatively, you might be interested in the os.walk function to take care of the recursive-ness for you.

提交回复
热议问题