4

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.

Community
  • 1
  • 1
Kev
  • 118,037
  • 53
  • 300
  • 385

2 Answers2

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.

Community
  • 1
  • 1
korro
  • 1,577
  • 13
  • 11
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#.

chilltemp
  • 8,854
  • 8
  • 41
  • 46