CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Does the file exists?

 



Wild_Thing
stranger

Oct 12, 2001, 6:13 AM

Post #1 of 4 (679 views)
Does the file exists? Can't Post

Let's say, script has information:
http://www.my.server.com/folderx/file.xxx

How can I get information that this file exists?



Pro_4
User

Oct 12, 2001, 2:42 PM

Post #2 of 4 (670 views)
Re: Does the file exists? [In reply to] Can't Post

OK im sure this works if its on your server but off your server not sure.

do something like this:
if (-e "http://www.my.server.com/folderx/file.xxx") { print "Yep its there"; } else { print "Nope cant seem to find it";}

Hope that helps :)


@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];


Cure
User

Oct 12, 2001, 9:59 PM

Post #3 of 4 (657 views)
Re: Does the file exists? [In reply to] Can't Post

Check a file that isn't on your server --->


use IO::Handle;
use IO::Socket qw(:DEFAULT :crlf);
use strict;

$/ = CRLF . CRLF;

my $host = 'www.url.com';
my $port = '80';
my $path = '/foobar.txt';



my $return = check($host,$port,$path);


if ($return) {
'the file foobar.txt exist'
}

else {
'the file foobar.txt does not exist'
}



sub check {
my($host,$port,$path) = @_;

socket SOCKET, PF_INET, SOCK_STREAM, getprotobyname('tcp');

SOCKET->autoflush(1);

connect SOCKET, sockaddr_in($port,inet_aton($host));

SOCKET->print("GET $path HTTP/1.1\nHost: $host",CRLF,CRLF);

my $header = <SOCKET>; # read the header
($header =~ m!Not Found!i) ? undef : 1

}





Cure



mhx
Enthusiast / Moderator

Oct 12, 2001, 10:06 PM

Post #4 of 4 (655 views)
Re: Does the file exists? [In reply to] Can't Post

You may find an answer here:

http://forums.perlguru.com/showflat.pl?Board=Forum7&Number=11108

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives