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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats my current directory? 2

Status
Not open for further replies.

Nebbish

Programmer
Apr 7, 2004
73
US
Hey all, kind of an easy question. I have a perl script which I've compiled into a .exe. When I execute it, it naturally sets its directory to the one the .exe is found in. This is fine. However, I want to know exactly what this directory is. For example, my script (.exe) file is under:

C:/Bob/Hope/myScript.exe

I execute it, and can open files in its present directory by doing things like

open(FILE, "< someFile.txt");

But, I want to know the directory structure leading up to the current directory (ie, in this case, C:/Bob/Hope/).

Anyone know?

-Nick
 
my $script = $0;
$script =~ s/^[\.\/\\]+//;
$ABSOLUTE_PATH = `pwd`;
chomp($ABSOLUTE_PATH);
$ABSOLUTE_PATH .= "/" . $script;
if ($ABSOLUTE_PATH =~ /(.*)\/([\w]+.exe)/) {
$ABSOLUTE_PATH = $1;
$script = $2;
}
 
In unix:

my $script = $0;
$script =~ s/^[\.\/\\]+//;
$ABSOLUTE_PATH = `pwd`;
chomp($ABSOLUTE_PATH);
$ABSOLUTE_PATH .= "/" . $script;
if ($ABSOLUTE_PATH =~ /(.*)\/([\w]+.exe)/) {
$ABSOLUTE_PATH = $1;
$script = $2;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top