En Wed, 27 Aug 2008 01:15:58 -0300, aditya shukla
<adityashukla19 83@gmail.comesc ribi�:
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
like this:
path = os.getenv("PATH ")
dirs = path.split(os.p athsep)
for dir in dirs:
fullfn = os.path.join(di r, your_applicatio n_name_includin g_exe_extension )
if os.path.isfile( fullfn):
# found
--
Gabriel Genellina
<adityashukla19 83@gmail.comesc ribi�:
I wanna know how can i extract path of a program whose path i have added
to
the PATH variable.
>
This is what i have done
>
import os
>
x=os.getenv("PA TH")
>
print x
>
Files\Microsoft SQL Server\90\Tools \binn\;C:\Progr am
Files\QuickTime \QTSystem\;C:\f older1\folder2\ prog
>
Now i have to extract the path of my program ie
(C:\folder1\fol der2\prog) .I
mean i can split the string using
>
y=x.split(';')
>
a=y[-1]
>
but i dont wanna do this way ,i wanna search for my program from this
list
and then return its path
to
the PATH variable.
>
This is what i have done
>
import os
>
x=os.getenv("PA TH")
>
print x
>
>>%SystemRoot%\ system32;%Syste mRoot%;%SystemR oot%\System32\W bem;c:\Program
Files\QuickTime \QTSystem\;C:\f older1\folder2\ prog
>
Now i have to extract the path of my program ie
(C:\folder1\fol der2\prog) .I
mean i can split the string using
>
y=x.split(';')
>
a=y[-1]
>
but i dont wanna do this way ,i wanna search for my program from this
list
and then return its path
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
like this:
path = os.getenv("PATH ")
dirs = path.split(os.p athsep)
for dir in dirs:
fullfn = os.path.join(di r, your_applicatio n_name_includin g_exe_extension )
if os.path.isfile( fullfn):
# found
--
Gabriel Genellina