Don't ask to ask, just ask | |
PerlMonks |
is this file open?by thnidu (Acolyte) |
on Dec 18, 2011 at 03:50 UTC ( [id://944153]=perlquestion: print w/replies, xml ) | Need Help?? |
thnidu has asked for the wisdom of the Perl Monks concerning the following question:
Honored monks:
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:
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,
Back to
Seekers of Perl Wisdom
|
|