I use Perl under WinXP and Mac OS X, but this question is specifically for WinXP (although I may want to port the script to Mac somedayP.
This script, index.pl, opens the current directory with the filehandle POSTED and looks for filenames beginning with a certain pattern, (/^(\d{6}[b-z]?) /). It analyzes each such filename with a series of regexps, then writes the results of its analysis for each filename to an output file (handle OUT) as tab-delimited text.
When it's done all such files -- when the while(($file = readdir(POSTED))) {...} loop is done -- it closes OUT and calls system to open it in NotePad.
Then I manually "select all" in NotePad, "copy", and close the file. The script then opens an Excel spreadsheet into which I paste the data for further manipulation. Here's the main code:
open(OUT, '>', 'index.txt') or die($!); &byfile; # subroutine to find, analyze, & write filenames printf STDERR ("%d lines processed\nwith header, " . "%d lines written to index.txt", $lines, $lines + 1); close(OUT); system("notepad index.txt"); system("index.xlsx");
Here's the problem: I often run this script iteratively to make sure that new files are getting treated properly, or when tweaking the program. At such times, I already have the spreadsheet open from the previous iteration. The script works all right, but I keep getting error messages on the terminal window: "The process cannot access the file because it is being used by another process." Not only is this a nuisance, but the script has wasted time (I don't know if any significant amount) in vainly trying to open a file that's already open.
My question, then: How can I test whether the spreadsheet is already "being used by another program" (namely, Excel)? I can't do a filehandle test because I didn't open it in Perl.
Respectfully awaiting enlightenment,
Your humble student Thnidu
In reply to is this file open? by thnidu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |