Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   How to check if a file is exist or not? (http://www.velocityreviews.com/forums/t896248-how-to-check-if-a-file-is-exist-or-not.html)

sureone@gmail.com 01-24-2006 01:36 AM

How to check if a file is exist or not?
 
Could anybody give a sample code for this question?

Thanks!


John W. Krahn 01-24-2006 01:50 AM

Re: How to check if a file is exist or not?
 
sureone@gmail.com 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

Samwyse 01-24-2006 05:53 AM

Re: How to check if a file is exist or not?
 
John W. Krahn wrote:
> sureone@gmail.com 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.

Juha Laiho 01-24-2006 03:20 PM

Re: How to check if a file is exist or not?
 
"John W. Krahn" <krahnj@telus.net> said:
>sureone@gmail.com 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)

Rich 01-24-2006 06:12 PM

Re: How to check if a file is exist or not?
 
In article <RJfBf.132810$km.93567@edtnps89>, John W. Krahn says...
>
>sureone@gmail.com 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



All times are GMT. The time now is 01:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.