Hi, I couldn't see what is wrong with logic.
Could you please explain to me?

That is the codes which was written by someone and I am just using it. When this codes was run in someone else application, I could delete the files manually although the application is still opened.

However if I copy the codes into my application, I couldn't delete the file at all, if my application is running.

But I think I have to give up on this.

I am sorry for bugging you two with the messy codes.
Thank You so much for helping.