[英]Why folders are locked on Windows XP and Windows Server 2003?
There is a problem that I can't safely remove a USB disk on XP and 2003 Server, because my application holds it. 我无法安全地删除XP和2003 Server上的USB磁盘,因为我的应用程序保存了它。 There is a folder on USB, in which some files are held.
USB上有一个文件夹,其中保存了一些文件。 I need to copy those files from USB to some destination folder on disk C:.
我需要将这些文件从USB复制到磁盘C:上的某个目标文件夹中。 After this is done I'm trying to safely remove disk and cannot do this because my application uses it.
完成此操作后,我试图安全删除磁盘,但无法执行此操作,因为我的应用程序使用了它。 Actually it holds the folder on USB where files that has to be copied are situated.
实际上,它将USB文件夹保存在必须复制文件所在的位置。 This is happening only on XP and 2003 server, but not in Windows 7. What could it be?
这仅在XP和2003服务器上发生,而在Windows 7中则没有。 I use methods from File class such as Copy , Exists , SetAttributes and methods from Path class.
我使用File类的方法,例如Copy , Exists , SetAttributes和Path类的方法。 Thanks in advance.
提前致谢。
Folders are shared objects, just like files. 文件夹是共享对象,就像文件一样。 You cannot remove a folder, or the drive on which it resides, until all handles on the folder are closed.
在关闭文件夹上的所有句柄之前,您无法删除文件夹或其所在的驱动器。
They tend to be hard to identify. 它们往往很难识别。 Most pernicious are the lock created when an app makes the folder its default working directory, equivalent of the .NET Environment.CurrentDirectory property.
最有害的是当应用程序将文件夹设置为默认工作目录(相当于.NET Environment.CurrentDirectory属性)时创建的锁。 Forgetting OpenFileDialog.RestoreDirectory is a standard trap.
忘记OpenFileDialog.RestoreDirectory是一个标准陷阱。 And when an app monitors the directory for changes, equivalent of the .NET FileSystemWatcher class.
当应用监视目录更改时,等效于.NET FileSystemWatcher类。 Just plain hard to see them.
只是很难看到他们。 Windows 7 and up make it a bit easier to deal with by allowing the volume to be ejected anyway.
Windows 7及更高版本允许以任何方式弹出该卷,从而使其处理起来更加容易。 Follow-up at superuser.com, there are no doubt utilities around that make this more visible.
在superuser.com上进行了后续跟踪,毫无疑问,实用程序可以使此操作更加明显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.