How to programmatically get a list of locked files in a folder structure?

Following this question: How can I unlock a file that is locked by a process in .NET , how to programmatically get a list of files that are locked in a specific folder and its subfolders?

I am using Windows 2003, .NET 3.5, C # 3.0.

Update: some background ... basically we archive closed websites on a shared server. After deleting the site from IIS, we move the folder structure for the site to the archive, where it was stored for 6 weeks. Although the IIS and FTP site were stopped and deleted, we still encounter locked files during the move. So it would be nice to know that he still has a lock.

+3
source share
2 answers

As another question answered: How to check file lock?

The only way is to try all of them and add them to the list if it throws an exception. As mentioned in the above question, it will not be a reliable list to be used, but it will give you a general idea of ​​a particular point in time.

+2
source

The only reliable way to detect locked files in real time is to write a device driver (e.g. filemon ), but I don’t know, I think you can do it in C #.

0
source

Source: https://habr.com/ru/post/1698797/


All Articles