473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 23958
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
8
by: hokiegal99 | last post by:
I installed Python-2.3 into c:\Program Files\Python23 on a new W2K SP4 computer. When I write a Python script and run it from the command prompt, I get the following error: C:\>python...
1
by: Alex | last post by:
Hello, in my company, we have a diagnostic tool for hardware. Depending on the hardware projcet, a different project configuration is needed. The configuration file is written in XML and...
15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
2
by: freak | last post by:
Sorry , corrections to my script Have a problem with spaces in the function popen Next example works fine: ... $drive="c:"; $path=""; $file="\\myfile.exe"">"; $call = $drive.$path.$file;...
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
3
by: Frank Millman | last post by:
Hi all I am writing a business/accounting application. Once a user has logged in they are presented with a menu. Each menu option has a description and an associated file name and program name....
4
by: Rafael Olarte | last post by:
Hello, Can anybody give me hint in how I to copy a file path and then output the same file path on a different *.txt file? This is the code I have: #include <iostream> #include <fstream>...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
12
by: =?ISO-8859-1?Q?Thomas_B=F8rlum?= | last post by:
Hey all, I'm writing a c++ program that needs to read a file. I'm trying to read a file that is in the same directory as the executable. Everything works fine if I execute the program while in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.