John,

I had a similar problem. This may be not perfect but works for me:

...
sub isfilelocked        {       # filename
  local $file, $rc;
        
  ($file) = @_;
  $rc = open(HANDLE, $file);
  $rc = flock(HANDLE, LOCK_EX|LOCK_NB);
  close(HANDLE);
  return !$rc;
}

# ...

while (time < $endtime) {
  opendir(DIR, $indir);
  @filelist = grep(/your_pattern_here/ , readdir(DIR));
  closedir(DIR);
  foreach $file (@filelist) {
    if (isfilelocked($file))    {
      # $file is locked by another process, skip
    } 
    else        {
      # process $file
    }
  }
  sleep($sleeptime);
}

...


regards
Andreas

-----Original Message-----
From: John Watson [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 14, 2000 7:27 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED];
Perl-Win32-Users@listserv. ActiveState. com
Subject: How to check if file is locked.


I have a perl script that processes files in directories and zips them up.

The problem I have is that some of the files may be in the process of being
copied into the directory I am monitoring while I am trying to zip them up.

I have tried to wait for the file to finish copying before zipping by
comparing the file sizes after a 5 second interval.  The only problem is
that windows states the total file size as soon as the file is visable in
the directory ( even if only 1% of the file is copied).

I have tried using Win32::File::GetAttributes as well as -s($file) with no
success.

Any ideas how I can check if the file is not locked ??


Thanks


John



_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin

Reply via email to