×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Files and probably something simple

Files and probably something simple

Files and probably something simple

(OP)
Ok, another problem...

I need to check if a file exists and if it doesn't exist, I need it to jump out of the loop.  I don't know the syntax for checking if a file is there.  I've looked in my book and online.  I just don't think I'm looking it up correctly.

Thanks for the help!

RE: Files and probably something simple

(OP)
Nevermind!!!!  I got it.

RE: Files and probably something simple

(OP)
The easiest way I've seen to do it is....

open(INFO, filename) ¦¦ die

in place of die you can put other things, next or last etc.

RE: Files and probably something simple

If you don't want to open a file to check if it exists, there is a bunch of test operators you can use.  Here's a quick summary of the most common:

-e    Does the file exist?
-z    Is the file zero length?
-s    Is the file non-zero length?
-r    Can I read the file?
-w    Can I write to the file?
-x    Can I execute the file?
-f    Is it a standard file?
-d    Is it a directory?
-T    Is it a text file?
-B    Is it a binary file?

Most of these imply the "-e" test.  For example, if you can read a file, then it must exist.  Here's a quick example that checks if we can execute a file and if it is a binary file.

#!/usr/bin/perl

$My_File = "/usr/bin/perl";

if ( -B $My_File && -x $My_File ) {
    print $My_File, " is an executable binary.\n";
}

Hope that helps.




--
0 1 - Just my two bits

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close