473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Re: Extracting path of a program from a list.

En Wed, 27 Aug 2008 01:15:58 -0300, aditya shukla
<ad**************@gmail.comescribi�:
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("PATH")

print x
>>%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\ System32\Wbem;c:\Program
Files\Microsoft SQL Server\90\Tools\binn\;C:\Program
Files\QuickTime\QTSystem\;C:\folder1\folder2\prog

Now i have to extract the path of my program ie
(C:\folder1\folder2\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
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.pathsep)
for dir in dirs:
fullfn = os.path.join(dir, your_application_name_including_exe_extension)
if os.path.isfile(fullfn):
# found

--
Gabriel Genellina

Aug 27 '08 #1
0 949

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andrew Edwards | last post by:
I have program that downloads a file from the internet and extracts it using calls to system(). All files are extracted into the directory where my program is located. How do I redirect the...
3
by: War Eagle | last post by:
I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox contains the full path to a file ... for example ...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
10
by: John | last post by:
Hi I am using openfiledialog to get user to select files and then I am extracting the files using filenames(). How can I now separate the file path from the actual filename? Thanks Regards
2
by: Daya Kiran Sunkara | last post by:
Hi All, I have a program which fetches the list of files inside a directory. For fetching this list I am making use of the glob.glob method which takes path as a parameter. For building the...
2
by: Robert McEuen | last post by:
Sorry if this double-posts...Google doesn't do a very good job of communicating whether something has posted or not. Using Access 97, WindowsXP Is there a way to pass command line parameters...
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
4
by: Debbiedo | last post by:
My software program outputs an XML Driving Directions file that I need to input into an Access table (although if need be I can import a dbf or xls) so that I can relate one of the fields...
4
by: Ant | last post by:
Hi all, My kids have a bunch of games that have to be run from CD (on Windows XP). Now they're not very careful with them, and so I have a plan. I've downloaded a utility (Daemon Tools) which...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.