OS reports: Access Denied

Hello.
I have scripts which sorting tables and make necessary preparations(checks/unzip/zip/copy to tmp folder) and it works fine.

Unfortunately when script process the folder(eg specific day of table) with empty data I get error: “OS reports: Access Denied”

Error occurs randomly in different lines of code(when it works with files).

Perhaps that is because q is too fast for working with very small files and I should add the small pause between operations…

Finally I decided to add a small delays using simple function with while.

Delay duration is approximately 10ms.

Problem disappeared.