Following up from this question: How can I unlock a file that is locked by a process in .NET, how do I programmatically get a list of files that are locked in a particular folder and its subfolders?
从这个问题开始:如何解锁由.NET中的进程锁定的文件,如何以编程方式获取锁定在特定文件夹及其子文件夹中的文件列表?
I'm using Windows 2003, .NET 3.5, C# 3.0.
我使用的是Windows 2003,.NET 3.5,C#3.0。
Update: some background... basically we're archiving closed websites on a shared server. After deleting the site from IIS we move the folder structure for the site to an archive where it's held for 6 weeks. Even though the IIS site and FTP has been stopped and deleted we still encounter locked files during the move. So it'd be nice to know upfront what's still got a lock on it.
更新:一些背景......基本上我们在共享服务器上存档封闭的网站。从IIS中删除该站点后,我们将该站点的文件夹结构移动到存档,并将其保存6周。即使IIS站点和FTP已被停止和删除,我们仍然会在移动过程中遇到锁定的文件。所以很高兴知道还有什么东西可以锁定它。
2 个解决方案
#1
2
As answered in another question :How to check for file lock?
在另一个问题中回答:如何检查文件锁?
The only way would be trying them all and add them to the list if it throws an exception. As mentioned in the above question, it would not be a reliable list to use, but only give you an overview of a specific point in time.
唯一的方法是尝试所有这些并将它们添加到列表中,如果它抛出异常。如上面的问题所述,它不是一个可靠的列表,但只能概述一个特定的时间点。
#2
0
The only reliable way to detect locked files in real time would be to write a device driver (like filemon), but I don't think you can do that in C#.
实时检测锁定文件的唯一可靠方法是编写设备驱动程序(如filemon),但我不认为你可以在C#中做到这一点。
#1
2
As answered in another question :How to check for file lock?
在另一个问题中回答:如何检查文件锁?
The only way would be trying them all and add them to the list if it throws an exception. As mentioned in the above question, it would not be a reliable list to use, but only give you an overview of a specific point in time.
唯一的方法是尝试所有这些并将它们添加到列表中,如果它抛出异常。如上面的问题所述,它不是一个可靠的列表,但只能概述一个特定的时间点。
#2
0
The only reliable way to detect locked files in real time would be to write a device driver (like filemon), but I don't think you can do that in C#.
实时检测锁定文件的唯一可靠方法是编写设备驱动程序(如filemon),但我不认为你可以在C#中做到这一点。