All I need to do is test to see if a file exists! Seems easy right? Well, apparently not. Below you will see a few things I have tried. The only thing that works is actually
chdir()'ing to the directory (notice that took two
chdir()'s to get there. When I was doing just one chdir() the script never
warn()'ed it just never actually got to the desired directory. When I wrote code to actually do a listing (using
readdir()) it was not in the destination directory that it said it was in...it was in the parent directory to that directory.
I checked permissions, I checked to make the file actually existed, I think I have checked all but the one thing causing my problem...this is why I am here.
my $funcName = (caller(0))[3];
my $player_name = shift;
my $mapname = shift;
(my $gamedir = &send(1,"sv_gamedir"))
=~ s/.*: (.*)\n+/$1/;
my $full_path = "$HOME/$gamedir/maps/$mapname.bsp";
# chdir("$HOME/$gamedir") or
# die("Cannot chdir to $HOME/$gamedir: $!\n");
# chdir("maps") or
# die("Cannot chdir to maps: $!\n");
# print "Current working directory: " . getcwd . "\n";
if ( -f $full_path ) {
print STDERR "Map exists! -> $HOME/$gamedir/maps/$mapname.bsp\
+n";
&send(0,"say Player name: $player_name map: $mapname");
} else {
print STDERR "Map does not exist! -> $HOME/$gamedir/maps/$mapn
+ame.bsp\n";
&send(0,"say Requested vote for map $mapname denied: map does
+not exist on this server");
}
----------
- Jim
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.