Tommi Prami 130 Posted March 15, 2023 (edited) Yellow all, https://github.com/TommiPrami/Delphi.GetProcessReservingFile Made quick and dirty port of code found from here: https://devblogs.microsoft.com/oldnewthing/20120217-00/?p=8283 If find anything to fix or make code better, feel free to send pull request or so... -Tee- Edited March 15, 2023 by Tommi Prami 2 2 Share this post Link to post
DelphiUdIT 177 Posted March 15, 2023 Really interesting, knowing if a file is already in use by another application via an api instead of trying to open it and manage the error (without knowing "who" is blocking it anyway) is very useful in some scenarios. Bye Share this post Link to post
Tommi Prami 130 Posted March 16, 2023 16 hours ago, DelphiUdIT said: Really interesting, knowing if a file is already in use by another application via an api instead of trying to open it and manage the error (without knowing "who" is blocking it anyway) is very useful in some scenarios. Bye This might be slow and resource intensive, depending on situation. My idea of pseudocode pattern would be something like. try FileOperations(LFileName); except on E: Exception do begin ... if GetProcessReservingFile(LFileName, LProcessFileName) then LErrorMessage := LErrorMessage + ' File is being used by ' + LProcessFileName; ... end; end; But everything depends on the situation. Anyhow, user most likely would like to know what app has the file is opened. -Tee- Share this post Link to post
uligerhardt 18 Posted March 16, 2023 FWIW: There's also IFileIsInUse. E.g. delphi - Checking if the file is in use and by which application? - Stack Overflow. But it only works for apps that support it. 1 Share this post Link to post
Tommi Prami 130 Posted March 16, 2023 3 hours ago, uligerhardt said: FWIW: There's also IFileIsInUse. E.g. delphi - Checking if the file is in use and by which application? - Stack Overflow. But it only works for apps that support it. Quite limited but interesting still. -Tee- Share this post Link to post