Re: Determining if a file is open
And yes, this is under Windows. (Vista) Jason On 2/18/2010 8:38 AM, Jason Lowder wrote: Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2693 - Release Date: 02/17/10 01:35:00 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
Excuse me for being in a rush and not having time to develop a sample, but I think what you want to do can be determined using WMI, in the CIM_Datafile class, there is a property named InUseCount: http://msdn.microsoft.com/en-us/library/aa387236(VS.85).aspx http://www.slideshare.net/ddn123456/win32-perl-wmi (Haven't checked that one out, but it says it is an introduction to using Perl and WMI) http://forums.cacti.net/about5816.html (Contains an example of using WMI in Perl). Almost all properties of windows objects can be found in some WMI class. You can also connect to remote machines and run WQL queries against those machines, so it is not just for local machines. If needed, I'll see if I can provide an example when I get off work today. Hopefully, this gets you going in the right direction. From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jason Lowder Sent: Thursday, February 18, 2010 7:20 AM To: perl-win32-users@listserv.ActiveState.com Subject: Re: Determining if a file is open And yes, this is under Windows. (Vista) Jason On 2/18/2010 8:38 AM, Jason Lowder wrote: Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.commailto:Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs No virus found in this incoming message. Checked by AVG - www.avg.comhttp://www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2693 - Release Date: 02/17/10 01:35:00 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
An easier solution is to try to open the file exclusively. If it fails, one of the errors will be unable to obtain the exclusive lock (because the file is open already). From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Steve Howard (PFE) Sent: Thursday, February 18, 2010 10:34 AM To: Jason Lowder; perl-win32-users@listserv.ActiveState.com Subject: RE: Determining if a file is open Excuse me for being in a rush and not having time to develop a sample, but I think what you want to do can be determined using WMI, in the CIM_Datafile class, there is a property named InUseCount: http://msdn.microsoft.com/en-us/library/aa387236(VS.85).aspx http://www.slideshare.net/ddn123456/win32-perl-wmi (Haven't checked that one out, but it says it is an introduction to using Perl and WMI) http://forums.cacti.net/about5816.html (Contains an example of using WMI in Perl). Almost all properties of windows objects can be found in some WMI class. You can also connect to remote machines and run WQL queries against those machines, so it is not just for local machines. If needed, I'll see if I can provide an example when I get off work today. Hopefully, this gets you going in the right direction. From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jason Lowder Sent: Thursday, February 18, 2010 7:20 AM To: perl-win32-users@listserv.ActiveState.com Subject: Re: Determining if a file is open And yes, this is under Windows. (Vista) Jason On 2/18/2010 8:38 AM, Jason Lowder wrote: Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.733 / Virus Database: 271.1.1/2693 - Release Date: 02/17/10 01:35:00 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
other things to experiment with; a. if the file may be successfully renamed, this implies its not being held open (clunky solution, as would require you to rename once, then again to bring it back to its original filename - but low tech), or b. sysinternals has a utility called 'handle.exe' that reports the pid of whatever process that has a file open. if it reports nothing, then nothing is holding the file open. -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jason Lowder Sent: Thursday, February 18, 2010 6:38 AM To: perl-win32-users@listserv.activestate.com Subject: Determining if a file is open Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
On Thu, 18 Feb 2010, Greg Aiken wrote: other things to experiment with; a. if the file may be successfully renamed, this implies its not being held open (clunky solution, as would require you to rename once, then again to bring it back to its original filename - but low tech), or This is not correct. You can rename a file that is in use (you cannot delete it when it is in use, but that doesn't help you much here). Trying to open the file for updating is a much simpler test to make sure nobody holds the file open for writing. Cheers, -Jan ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
Hi, Someone may have a better option, but one way to do it would be to use the external program 'handle' available from sysinternals (http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx) . You could see if the file was open using this command - of course you could encounter a race condition if the other process then opens the file before you open it (not sure if this is a possibility or not). Ken -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jason Lowder Sent: Thursday, February 18, 2010 9:38 AM To: perl-win32-users@listserv.ActiveState.com Subject: Determining if a file is open Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs