codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Checking for a File that Does Not Exist (Yet)  hyliandanny at 04:10 on Tuesday, June 10, 2008
 

Hi,

I was wondering how I could check for a file until it finally exists. The high-end depiction:

1. User runs my perl script, my perl script starts checking for files to read.
2. User runs another program which generates files.
3. My perl script reads the files as they are created by the other program.

The names of the files are already pre-determined, so there's no need for me to dynamically determine what has been created, or anything fancy like that. My script just wants to read x.txt, and I know it's not going to exist until later; this is what I have now:


open(COMM, "<", "/forum/CFPSTestComm.txt" || print "trying to open file");
while(!COMM)
{
open(COMM, "<", "/forum/CFPSTestComm.txt" || print "still trying to open file.");
}

Is there a better way to check until the file exists?

  Re: Checking for a File that Does Not Exist (Yet)  mimir at 04:52 on Tuesday, June 10, 2008
 

im not sure how cpu demanding your method is.
if it seems to be a bit too demanding of the cpu then just add a sleep 1; in there.

open(COMM, "<", "/forum/CFPSTestComm.txt" || print "trying to open file");
while(!COMM)
{
open(COMM, "<", "/forum/CFPSTestComm.txt" || print "still trying to open file.");

sleep 1;
}








otherwise there's always the

while !(-e "/forum/CFPSTestComm.txt")
{
open(COMM, "<", "/forum/CFPSTestComm.txt" || print "still trying to open file.");

sleep 1;
}

  Re: Checking for a File that Does Not Exist (Yet)  hyliandanny at 05:31 on Tuesday, June 10, 2008
 

Thanks for the reply!

I tried that -e solution, but my script closes immediately after running. I'm assuming it is some flag to check that the file exists, but if not, could you enlighten me?


  Re: Checking for a File that Does Not Exist (Yet)  mimir at 05:57 on Tuesday, June 10, 2008
 

#oops, it was supposed to be with extra brackets around the "!":

while (!(-e "/forum/CFPSTestComm.txt"))
{
open(COMM, "<", "/forum/CFPSTestComm.txt" || print "still trying to open file.");

sleep 1;
}



#and yes the -e option is to check if file exists.











CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Array within array
•  Hey all could some 1 help me ?? thanks
•  Re: Checking for a File that Does Not Exist (Yet)
•  mouse trailer
•  Problems in login using WWW::Mechanize
•  using javascript to embed videos
•  Re: really lost my syntax
•  Urgent:- Please help me out with error XML:Parser no element found
•  Urgent:- Please help me out with error XML:Parser no element found


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008