How to check if a file is exist or not?

Discussion in 'Perl Misc' started by sureone@gmail.com, Jan 24, 2006.

  1. Guest

    Could anybody give a sample code for this question?

    Thanks!
     
    , Jan 24, 2006
    #1
    1. Advertising

  2. wrote:
    > Could anybody give a sample code for this question?


    if ( -e 'filename' ) {
    print "'filename' exists.\n";
    }


    perldoc -f -e
    perldoc -f stat


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Jan 24, 2006
    #2
    1. Advertising

  3. Samwyse Guest

    John W. Krahn wrote:
    > wrote:
    >
    >>Could anybody give a sample code for this question?

    >
    > if ( -e 'filename' ) {
    > print "'filename' exists.\n";
    > }



    John, John, John. *sigh* You didn't answer his question. You should
    have said, "Yes", and then given the perldoc references.
     
    Samwyse, Jan 24, 2006
    #3
  4. Juha Laiho Guest

    "John W. Krahn" <> said:
    > wrote:
    >> Could anybody give a sample code for this question?

    >
    >if ( -e 'filename' ) {
    > print "'filename' exists.\n";
    > }


    However, be careful if later on performing any action based on the
    knowledge that at some point in the history the file did exist.

    Most often, one is interested, whether a piece of data can be read
    from a file - and in this context it'd be better to attempt to
    open the file and read the data. Just encapsulate the functionality
    performing this to allow an upper level to process and report the
    error appropriately.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Jan 24, 2006
    #4
  5. Rich Guest

    In article <RJfBf.132810$km.93567@edtnps89>, John W. Krahn says...
    >
    > wrote:
    >> Could anybody give a sample code for this question?

    >
    >if ( -e 'filename' ) {
    > print "'filename' exists.\n";
    > }
    >
    >
    >perldoc -f -e
    >perldoc -f stat
    >
    >
    >John


    Thanks for the perldoc tip. I've used it for different modules I've had to work
    with, but haven't tried to for basic usage. Usually rely on my O'Reilly manual
    as a cheat sheet for information like that, but now I have a quicker solution.

    Rich
    --
    Newsguy -- http://newsguy.com
     
    Rich, Jan 24, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Y.S.
    Replies:
    3
    Views:
    1,081
    strajan
    Sep 17, 2003
  2. LT
    Replies:
    7
    Views:
    2,147
    Phlip
    Jul 25, 2004
  3. praba kar
    Replies:
    1
    Views:
    428
    Michael Hoffman
    Apr 9, 2005
  4. Sidharth Kuruvila
    Replies:
    0
    Views:
    3,157
    Sidharth Kuruvila
    Apr 9, 2005
  5. Markus Mohr
    Replies:
    7
    Views:
    275
    Thomas 'PointedEars' Lahn
    Nov 28, 2003
Loading...

Share This Page