473,396 Members | 2,036 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,396 software developers and data experts.

directories problem

I'm trying to write a script in python to run several other python
scripts using os.system(scriptName). Many of those other scripts have
lines in them which look something like:
doSomething('config.txt')
where config.txt is a file in the same directory as scriptName. When I
run scriptName from its own directory, it is able to find config.txt.
But when I run scriptName from another directory, it can't find the file
because it's looking in the directory of the script which called it
rather than its own directory. Is there any way around this?

Lowell
Jul 18 '05 #1
4 1104
I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution for
that: can a python script know its own full path name?

Dan

"Lowell Kirsh" <lk****@cs.ubc.ca> wrote in message
news:ci**********@mughi.cs.ubc.ca...
I'm trying to write a script in python to run several other python scripts
using os.system(scriptName). Many of those other scripts have lines in
them which look something like:
doSomething('config.txt')
where config.txt is a file in the same directory as scriptName. When I run
scriptName from its own directory, it is able to find config.txt. But when
I run scriptName from another directory, it can't find the file because
it's looking in the directory of the script which called it rather than
its own directory. Is there any way around this?

Lowell

Jul 18 '05 #2
Dan Perl wrote:
I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution for
that: can a python script know its own full path name?


See near the end of this thread:
http://groups.google.ca/groups?threa...ing.google.com

Also note that scripts other than the main one can do it even more
easily: __file__, or if that's not always an absolute path,
os.path.abspath(__file__).

-Peter
Jul 18 '05 #3
Many thanks, Peter! Just like someone in the thread you are mentioning, I
have to go now and change a few scripts that I have.

And I guess that should give a solution for Lowell also. In each script
that's called with os.system( ), get the path of the script (use
os.path.split) and append the 'config.txt' file (use os.path.join).

Dan

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:_6********************@powergate.ca...
Dan Perl wrote:
I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution for
that: can a python script know its own full path name?


See near the end of this thread:
http://groups.google.ca/groups?threa...ing.google.com

Also note that scripts other than the main one can do it even more
easily: __file__, or if that's not always an absolute path,
os.path.abspath(__file__).

-Peter

Jul 18 '05 #4
Thanks Peter! I'm eager to try this out. It seems like a much cleaner
solution than all the other options I've been considering.

Lowell

Peter Hansen wrote:
Dan Perl wrote:
I'm not sure whether this is what Lowell is looking for, but I've been
looking at a similar problem and I would also like to see a solution
for that: can a python script know its own full path name?

See near the end of this thread:
http://groups.google.ca/groups?threa...ing.google.com
Also note that scripts other than the main one can do it even more
easily: __file__, or if that's not always an absolute path,
os.path.abspath(__file__).

-Peter

Jul 18 '05 #5

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

Similar topics

2
by: T. Kaufmann | last post by:
Hi there, in my directory are some 'normal' files like *.py sources and some empty directories too. How can I put all togehter into a zip-archive? There is no problem to zip the *.py files but...
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
6
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
1
by: Senthil | last post by:
Con is the file name for a reserved device name(i think it is for console). So you cannot create a file with name 'con'. choose some other name senthil >-----Original Message----- >Hi...
3
by: Stelrad Doulton | last post by:
Hi, I am having a strange problem on IIS 6.0. I am trying to create directories under a virtual directory on the fly to which I will upload files and retrieve these files later. I am having 2...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: rn5a | last post by:
A ListBox lists all the folders & files existing in a directory named 'MyDir' on the server. Assume that the ListBox lists 2 directories - 'Dir1' & 'Dir2' i.e. these 2 directories reside in the...
6
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
4
by: Jeff Nyman | last post by:
Greetings all. I did some searching on this but I can't seem to find a specific solution. I have code like this: ========================================= def walker1(arg, dirname, names):...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.