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

script path, environment variable

Status
Not open for further replies.

ivtmes

Programmer
Feb 12, 2001
3
US
How can I get the current path of an script.
I'm in a Windows environment and %ENV doesn't have a key for that purpose (or I can't find it).
Mi specific problem is that I want to dynamically include a folder with a path relative to my script.

thanks
 
You can use the same syntax you would to access the folder when you're on the command line. the following will all work:
"../../file.txt"
"relative/folder/file.txt"
"/absolute/folder/path/file.txt"

This is the syntax in *nix, but it sould work exactly the same in windows. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
I use this trick to open a ini file in the same directory as the script. I suppose you could a /../.. if required.

# Set the file value
$my_file = "file.ini";

# Get the directory where script.pl is located
$my_directory = dirname($0);

# Set the ini file object
open(SOURCE, &quot;< $my_directory/$my_file&quot;);


Thierry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top