in reply to delete file

If you are on Windows, you have to close the files before you can delete them.

Also make sure you're in the right directory when you use relative paths.

And there's no need for a loop, unlink accepts a list of files to delete as arguments.