Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Search a file

Reply
Thread Tools

Search a file

 
 
backgoodoo@gmail.com
Guest
Posts: n/a
 
      09-04-2008
Hello

Does anyone know how to find out whether a file exists or not?

TIA
 
Reply With Quote
 
 
 
 
David Precious
Guest
Posts: n/a
 
      09-04-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hello
>
> Does anyone know how to find out whether a file exists or not?


if (-f $filename) {
# $filename is a file which exists
}

Full list of tests:
http://perldoc.perl.org/functions/-X.html

A couple of seconds Googling probably would have found you the answer.

Cheers

David Precious
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-04-2008
On Sep 4, 1:42*pm, (E-Mail Removed) wrote:
> Does anyone know how to find out whether a file exists or not?


if (-e 'file.txt') {
print "file.txt exists\n";
} else {
print "file.txt does not exist\n";
}
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-04-2008
(E-Mail Removed) wrote:
>Does anyone know how to find out whether a file exists or not?


perldoc -f -e

jue
 
Reply With Quote
 
backgoodoo@gmail.com
Guest
Posts: n/a
 
      09-04-2008
On Sep 4, 2:07*pm, David Precious <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Hello

>
> > Does anyone know how to find out whether a file exists or not?

>
> if (-f $filename) {
> * * *# $filename is a file which exists
>
> }
>
> Full list of tests:http://perldoc.perl.org/functions/-X.html
>
> A couple of seconds Googling probably would have found you the answer.
>
> Cheers
>
> David Precious


Let me clarify my question again.

I want to search a file I do not know where it is but know its name
such as "text.exe".
So I want to check whether or not it is under c:\program file and sub
folders.

TIA
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      09-04-2008
(E-Mail Removed) writes:

> Let me clarify my question again.


Not that it matters, but this seems more like an entirely different
question than a clarification of the original.

> I want to search a file I do not know where it is but know its name
> such as "text.exe".


Have a look at the File::Find module.

sherm--

--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      09-04-2008
(E-Mail Removed) wrote:
>> (E-Mail Removed) wrote:
>> > Does anyone know how to find out whether a file exists or not?

>
>I want to search a file I do not know where it is but know its name
>such as "text.exe".


Don't you think those two requirements are quite different?

Anyway, the File::Find module has functions to search for the location
of a given file.

jue
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      09-04-2008
(E-Mail Removed) wrote in news:8e4ae12c-3235-4112-a476-2104557c2936
@p31g2000prf.googlegroups.com:

> On Sep 4, 2:07*pm, David Precious <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>> > Hello

>>
>> > Does anyone know how to find out whether a file exists or not?

>>
>> if (-f $filename) {
>> * * *# $filename is a file which exists
>>
>> }
>>
>> Full list of tests:http://perldoc.perl.org/functions/-X.html


....

> Let me clarify my question again.


You did not ask a clear question to begin with and this is the first
time you are clarifying the question, so the 'again' above is not
necessary

> I want to search a file I do not know where it is but know its name
> such as "text.exe".
> So I want to check whether or not it is under c:\program file and sub
> folders.


perldoc File::Find

I also like:

http://search.cpan.org/~texmec/File-Find-Iterator-0.4/

#!/usr/bin/perl

use strict;
use warnings;

use Data:umper;
use File::Find::Iterator;
use File::Spec::Functions qw( canonpath );

my $find = File::Find::Iterator->create(
dir => [ $ENV{TEMP} ],
filter => sub { /t\.pl\z/ },
);

while ( my $found = $find->next ) {
print "$found\n";
}

__END__




--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
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
Google search result like site search!! How? =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?= ASP .Net 3 05-06-2005 02:08 AM
removing search engines from the search bar whatever.or.not@gmail.com Firefox 1 02-17-2005 12:06 PM
Search Bar not displaying search Engines Zimran Douglas Firefox 1 01-07-2005 02:30 PM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM



Advertisments