开发者

How do I delete a folder that another process has open?

I created two services. I want to delete a folder, but that folder is used by my first service. When I execu开发者_JAVA百科te the first service after that I execute the second service it works fine. But when I try to execute both service at the same time it does not work properly.


Actually, the question should have been "What in the application could prevent folder from deletion by other applications".

Possibilities are:

  1. Your service opens some file in that folder and does not close it. Check all files that you are opening in the service, and close the ones which are in that folder.
    How files are closed depends on how they were opened. If you used CreateFile(), then close with CloseHandle(). If it was TFileStream, then just Destroy it.

  2. Your service has that folder set as the current directory. Choose other directory as a current with SetCurrentDir.


you cannot delete it unless, you can tell the other service by sending message to stop using the folder(or its content) before deleting it.


If first service is launched before second service then you can delete folder but if both services are launched together then you can't delete folder.

Only difference is you allowed time for first service to finish working with the folder.

Things to consider:

If your first service is using the folder then you won't be able to delete it until your service closes connection with that folder like already mentioned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜