Jump to content

Patrick Hughes

Members
  • Content Count

    6
  • Joined

  • Last visited

Everything posted by Patrick Hughes

  1. I've tried a number of "FileInUse" routines and for one reason or another they fail to capture the status of a file that is in use within its native application. So I came up with my own which appears to function properly. But I'm wondering how safe it may be so that it doesn't damage the original file. here's my code: function FileReallyIsInUse(fName: string): boolean; var Stream: TFileStream; begin result := false; try try Stream := TFileStream.Create(fName, fmCreate or fmShareDenyNone); //fmShareExclusive); //Stream.Seek(0, soFromBeginning); // (resulting file was 0 bytes) except on E:Exception do result := true; end; finally Stream.Free; end; end; What could possibly go wrong? Thanks for your thoughts and/or warnings. Patrick Hughes
  2. Note, before arriving at the point in my program where this function is used I've already gone through several iterations of FindWindow, FindWindowEx, etc. The trouble arises in some particular applications that do not use an MDIClient window arrangement or other window variations.
  3. Thanks for the heads up Tim, yes network files are included and can be a big part of my need. I'll check out the link. Rollo62, it is indeed a monitoring application, a time logger.
  4. I've already populated my data structure with file information that I'm monitoring including the filename, application that has opened it, the window handles (parent and child0 that contains the document, etc. I'm just trying to finalize my logging once the file is closed.
  5. As far as a race condition, I'm not too concerned since I'm polling every second and I'm not doing anything to the file, not even reading its contents. As for my original function it seemed to work several time but failed on subsequent attempts. Regarding the other function options presented none provide accurate results. Seriously, try them on a known file open in another application, such as an .xlsx in Excel or .docx in Word. See what result you get while the file is open (should return true) then the result after it's closed (should return false). I have working code that allows me to make a true determination but it involves retrieving all desktop handles and consumes massive page faults that I'm trying to eliminate. In any event that you all for your input.
  6. When I included the Stream.Seek(0, soFromBeginning); line it did. When I commented it out the file remained intact. I'll give yours a tryr
×