如何删除另一个进程已打开的文件夹? [英] How do I delete a folder that another process has open?

查看:75
本文介绍了如何删除另一个进程已打开的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个服务.我想删除一个文件夹,但是我的第一个服务使用了该文件夹.当我在执行第二项服务之后执行第一项服务时,它可以正常工作.但是当我尝试同时执行两个服务时,它无法正常工作.

I created two services. I want to delete a folder, but that folder is used by my first service. When I execute 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".

可能性是:

  1. 您的服务将打开该文件夹中的某些文件,但不会将其关闭.检查您正在服务中打开的所有文件,然后关闭该文件夹中的文件.
    文件如何关闭取决于文件的打开方式.如果使用CreateFile(),则使用CloseHandle()关闭.如果是TFileStream,则将其销毁.

  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.

您的服务已将该文件夹设置为当前目录.通过SetCurrentDir选择其他目录作为当前目录.

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

这篇关于如何删除另一个进程已打开的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆