Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to check if a file is exist or not?

Reply
Thread Tools

How to check if a file is exist or not?

 
 
sureone@gmail.com
Guest
Posts: n/a
 
      01-24-2006
Could anybody give a sample code for this question?

Thanks!

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      01-24-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Samwyse
Guest
Posts: n/a
 
      01-24-2006
John W. Krahn wrote:
> (E-Mail Removed) 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.
 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      01-24-2006
"John W. Krahn" <(E-Mail Removed)> said:
>(E-Mail Removed) 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)
 
Reply With Quote
 
Rich
Guest
Posts: n/a
 
      01-24-2006
In article <RJfBf.132810$km.93567@edtnps89>, John W. Krahn says...
>
>(E-Mail Removed) 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Does my object exist? So why its HWND doesn't exist? That's a question... (CMonthCalCtrl control) LT C++ 7 07-25-2004 07:08 PM
Can the Favourites Sidebar (IE, Opera, etc.) be addressed selectively (exist or non-exist)? Markus Mohr Javascript 7 11-28-2003 12:20 AM
In Schema, how to say "If one element exist, another element must exist"? Y.S. XML 3 09-17-2003 02:51 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments