473,473 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

The file executing

How does one get the path to the file currently executing (not the
cwd). Thank you

Jul 3 '07 #1
5 1124
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you
os.path.dirname(sys.argv[0])

Jul 3 '07 #2
On Jul 2, 9:47 pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you

os.path.dirname(sys.argv[0])
The returns the file that was called first, but not the one currently
executing...

Jul 3 '07 #3
On Jul 3, 8:56 am, Sebastian Wiesner <basti.wies...@gmx.netwrote:
[ Benjamin <musiccomposit...@gmail.com]
On Jul 2, 9:47 pm, Justin Ezequiel <justin.mailingli...@gmail.com>
wrote:
On Jul 3, 9:40 am, Benjamin <musiccomposit...@gmail.comwrote:
How does one get the path to the file currently executing (not the
cwd). Thank you
os.path.dirname(sys.argv[0])
The returns the file that was called first, but not the one currently
executing...

Use __file__ instead of sys.argv[0]
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)
>
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)

signature.asc
1KDownload

Jul 6 '07 #4
En Fri, 06 Jul 2007 17:15:22 -0300, Benjamin <mu**************@gmail.com>
escribió:
How does one get the path to the file currently executing (not the
cwd). Thank you
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)
I think you meant to test for "__main__", but anyway, this should be
enough:
currentDir = os.path.dirname(__file__)
or perhaps os.path.dirname(os.path.abspath(__file__)). Try to determine
that early in your program because __file__ may contain a relative path
(and will give a wrong result after changing the current directory).

--
Gabriel Genellina

Jul 9 '07 #5
On Jul 9, 6:42 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Fri, 06 Jul 2007 17:15:22 -0300, Benjamin <musiccomposit...@gmail.com
escribió:
How does one get the path to the file currently executing (not the
cwd). Thank you
So:
if __name__ == "main":
currentDir = os.path.dirname(sys.argv[0])
else:
currentDir = os.path.dirname(__file__)

I think you meant to test for "__main__", but anyway, this should be
Yes
enough:
currentDir = os.path.dirname(__file__)
or perhaps os.path.dirname(os.path.abspath(__file__)). Try to determine
that early in your program because __file__ may contain a relative path
(and will give a wrong result after changing the current directory).
I do it right at the top of the first module. Thanks for the help.
>
--
Gabriel Genellina

Jul 9 '07 #6

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

Similar topics

6
by: vishal | last post by:
hi how can i get the file name from which the current executing file is called. i m making a scrript which will be called from many other scripts. this script performs some calculation and then...
9
by: TS | last post by:
i have code that creates assemblies and classes from the assemlby and methods from the classes to set properties of dynamically created controls. How i should go about validating the assemblies,...
7
by: David R. | last post by:
Hello all, I would like to generate a Sql-Script-File and a Batch-File to execute the Batch-File over C#-Code and use the SQL-File as an Input-File for the command "osql" in the Batch-File. I...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
0
by: seye.ojumu | last post by:
Hello, I'm trying to nail down an issue and I'm not entirely sure what is wrong. It is this "loading pages that share a session problem." The solution, as I've read many places, should be to...
5
by: Eugene Anthony | last post by:
ds1.Tables.Rows.ItemArray.GetValue(0).ToString() contains the string path: images/5/Video1/qbert.flv if (File.Exists(ds1.Tables.Rows.ItemArray.GetValue(0).ToString())) { //code to execute } ...
7
by: CodeGrommet | last post by:
I'm testing out the system() command. I coded the following. How can I output the results into the given output file? Your help will be appreciated. /* system example : DIR */ //code based...
2
by: RaviRajhulk | last post by:
I have tried executing executing a batch file from a perl code using system("start c:\\temp\\sample.bat") but it is not executing ,Is there any way to execute batch file from a perl code
5
by: Arodicus | last post by:
I'm trying to get the pathname of the .js file that the currently-executing function resides in. This is useful if your .js file loads other assets within (or based on) the directory your .js file is...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.