Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the complete path of a file

Status
Not open for further replies.

Tve

Programmer
Joined
May 22, 2000
Messages
166
Location
FR
Hi,

I an trying to obtain the full directory of a passed file to a perl script (NT platform).

If the passed file is provided with a full directory, eg: C:\scripts\perl.pl X:\transfer\foo.txt, I suppose I could split on "\" and manipulate this data.

But if the perl script is located in X:\transfer, then the path name would not be included in the passed file name, eg: X:\transfer\perl.pl foo.txt.

I've tried File::Basename; standad module, but this only returns a relative path.

use File::Basename;
$path = dirname($ARGV[0]);

Value for $path is .

I don't know where to look anymore. Does somebody have an idea?

 
have you looked at the $ENV{'PATH'} entry? "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
$0 gives you the directory and filename of the perl script you're running. If you chop the filename off it you will have the path to any files passed using just the filename on the command line. Is this what you mean? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
ooo, my bad, sorry. ignore my post. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
<grin> Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
i find that only gives me the filename, but this gives me the path

use Cwd;
$thisdir = cwd();
 
This should also work for getting your current working directory on a *nix system:
Code:
$thisdir = chomp `pwd`;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top