$file = "/path/to/file.txt";

if (-e $file) {
        print "Yep, that file exists\n";
} else {
        print "Nope. Not there\n";
}

For more on the file test operators see perldoc -f -X

HTH

John



-----Original Message-----
From: Ned Cunningham [mailto:[EMAIL PROTECTED]]
Sent: 04 February 2002 14:47
To: '[EMAIL PROTECTED]'
Subject: Checking if a file exists.



Please help.

I need to check if a files exists in the root of c.  I would like to use if
else to control the response.  I have tried to check the file and verify $!,
but it seems to give me a problem.

Can anyone help?

#!/usr/bin/perl
 $sysname = `hostname`; 
 $nsname = substr($sysname,0,5);
 $tname = "shop1";
 $ttname = "shop2";
 $syroot = "\\\\shop1\\c\\loadvast.txt";

      if ($nsname eq $tname) {

      (`xcopy "d:\\loadvast.txt" "c:\\" /I`);
   
                             }

      open TESTF, $syroot;
      
      if ($! eq "") {

      print "good";

       if ($nsname eq $ttname) {
    
        close TESTF;

        (system 'erase "\\\\shop1\\c\\loadvast.txt"');

                              }
  
     } else { 
 
       print "bad";
        
          }




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to