views:

672

answers:

2

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?

I'm using 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.

+2  A: 

As answered in another question :http://stackoverflow.com/questions/1304/checking-for-file-lock-in-c

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.

korro
A: 

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#.

chilltemp