469,267 Members | 1,085 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

How do I get the path of the program file?

I need to get the filename and path of a program file from within that
file.

I've tried the $0 variable but that doesn't work. It gives the path from
the command that called the file. This is a problem when you use
.../../programfilename and need the actual full path.

How do I get it?

--
Mark Healey
marknews(at)healeyonline(dot)com

Oct 14 '05 #1
4 23620
rugrat
4
PerlDiver Hi Mark, A really easy way to find the path is to run a short script named perldiver.cgi You can download a copy of it at PerlDiver You can use this script to find out different things about your server besides paths. Otherwise, seeing as you already know the filename (you posted .../../programfilename ,start with the root path and trace it directly to the program. Hope this helps. Dave :)
Oct 15 '05 #2
Mark Healey wrote:
I need to get the filename and path of a program file from within that
file.

I've tried the $0 variable but that doesn't work. It gives the path from
the command that called the file. This is a problem when you use
../../programfilename and need the actual full path.

How do I get it?


I don't completely understand your issue. Perhaps the following is in
the direction.

#!/usr/bin/perl -w

use File::Basename;
my $name = "/a/b/c/d/e/filename";
my $path = basename($name);
$file = dirname($name);
print $path, " is located in ", $file, "\n";
exit;

Otherwise check which(1)

--
Regards,
Ton 't Lam
Oct 18 '05 #3
> I need to get the filename and path of a program file from within that
file.

I've tried the $0 variable but that doesn't work. It gives the path from
the command that called the file. This is a problem when you use
../../programfilename and need the actual full path.

How do I get it?


You can "canonify" $0, so that instead of a relative path
(../../programfilename) you have a fully qualified path
(/path/to/programfilename).

The easiest way to do this is:

use Cwd qw(realpath);
my $fullpath = realpath($0);

-- Lars

--
la****@hotmail.com

Nov 22 '05 #4
It seems $0 behavs differently from system to system. I only get a filename when I use $0 but I can use $^X.
Feb 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hal Vaughan | last post: by
8 posts views Thread by hokiegal99 | last post: by
15 posts views Thread by (Pete Cresswell) | last post: by
10 posts views Thread by wo_shi_big_stomach | last post: by
3 posts views Thread by Frank Millman | last post: by
11 posts views Thread by cybervigilante | last post: by
12 posts views Thread by =?ISO-8859-1?Q?Thomas_B=F8rlum?= | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.