Read dos.library autodoc for functions:
dos.library/LockDosList
dos.library/NextDosEntry
dos.library/UnLockDosList
Remember that you shouldn't call any high level functions (esp not dos I/O!) while keeping the dos list lock. In most cases you need to build a list to memory and only process it after UnLockDosList.