Skip to content
Advertisement

How to skip first few files when looping using os.listdir(path)?

I am using os.listdir(path), However, I want to skip the first few files available in the path.

JavaScript

ALL THE FILES IN PATH ARE NAMED AND SORTED. For example, file0000, file0001, file0002 ..etc What I can use to skip say first 5 files and use the rest of other files.

Advertisement

Answer

os.listdir doesn’t guarantee order, so you should sort first to make sure, then you can just slice:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement