Extracting path of a program from a list.
gagsl-py2 at yahoo.com.ar
Wed Aug 27 06:57:37 CEST 2008
En Wed, 27 Aug 2008 01:15:58 -0300, aditya shukla
<adityashukla1983 at gmail.com> escribi�:
> I wanna know how can i extract path of a program whose path i have added
> the PATH variable.
> This is what i have done
> import os
> print x
> Files\Microsoft SQL Server\90\Tools\binn\;C:\Program
> Now i have to extract the path of my program ie
> (C:\folder1\folder2\prog) .I
> mean i can split the string using
> but i dont wanna do this way ,i wanna search for my program from this
> and then return its path
Can't you get the program name and path from the place you got it
originally, before adding it to the PATH variable?
Or store it in some other place. I think it's a lot safer that way.
Anyway, once you split the PATH, you get a list. You should iterate over
the list looking if your program is located on each directory... Something
path = os.getenv("PATH")
dirs = path.split(os.pathsep)
for dir in dirs:
fullfn = os.path.join(dir, your_application_name_including_exe_extension)
More information about the Python-list