我无法删除目标文件,因为它被另一个进程使用 [英] I am unable to delete the destination file as it is used by another process

查看:163
本文介绍了我无法删除目标文件,因为它被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将文件复制到另一个目标后,我想从原始文件中删除该文件。

我无法这样做,因为另一个进程使用了​​文件



File.Copy(FullPath,strErrorFile,true);

File.Delete(FullPath);

解决方案

找出使用该文件的进程



Quote:

如何找出使用文件的句柄或DLL

Open Process Explorer,以管理员身份运行。

输入键盘快捷键Ctrl + F.另外,单击查找菜单并选择查找句柄或DLL。

将打开搜索对话框。

键入锁定文件的名称或其他感兴趣的文件。





(还有其他方法--SysInternals的Process Explorer *可能*帮助)



如果它是你自己的进程,你可能需要在复制和删除之间延迟或者某些其他方法刷新/强制你的进程放开文件


< blockquote>你需要调查发生了什么。要做到这一点,首先阅读我对此主题的过去答案:如何压缩错误'它已被使用通过vb.net中的另一个进程 [ ^ ]。



-SA


after copying the file to another destination i want to delete the file from origin.
I am unable to do so as file is used by another process

File.Copy(FullPath, strErrorFile, true);
File.Delete(FullPath);

解决方案

find out which process is using the file

Quote:

How to find out which handle or DLL is using a file
Open Process Explorer, running as administrator.
Enter the keyboard shortcut Ctrl+F. Altenatively, click the "Find" menu and select "Find a Handle or DLL".
A search dialog box will open.
Type in the name of the locked file or other file of interest.



(there are other ways of doing that - Process Explorer from SysInternals *may* help)

if it's your own process, you may need a delay between the copy and delete or some other method of flushing/forcing your process to let go of the file


You will need to investigate what's going on. To do so, start with reading my past answer on this topic: how to compress the error 'it is already used by another process' in vb.net[^].

—SA


这篇关于我无法删除目标文件,因为它被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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