472,368 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Using Python scripts in Windows Explorer (.bat and directories)

1
Sheesh!

I was doing research on using batch files as drop targets when I came across a python discussion thread on this site with the same topic. I thought I would share what I had learned (the hard way), but I could find no way to reply to that thread (even after registering!).

Anyway, wrapping the python script in a batch file is a good idea, but I believe the problem the python programmer was encountering was how Windows automatically sets the working directory when passing a file via "drop target".

So the answer was actually in the third post of that thread, but nobody called attention to the fact it would be necessary to change to the directory where the necessary files exist.

Since Windows does provide parameter 0 (the complete pathname of the batch file), you can do something like this (in Windows XP, i.e. with command extensions):

REM Lame way to ensure we are in the same directory as batch file
%~d0
cd %~p0

Where the first line simply evaluates to the drive letter and the second line evaluates the path. When processed by the command shell the commands might look like this:

c:
cd bin\scripts\test

Hopefully you get the idea. This sets the working directory to the same as directory as where the batch file resides. You could change this to explicitly set the directory to whatever you want.

Maybe you found all this out, but I didn't see any wrap up mail so I thought I would post.

Well, if this doesn't help the original poster, maybe it will help somebody else who ends up beating their head into the wall over this completely ridiculous, unintuitive behavior.
Nov 3 '06 #1
1 3923
bartonc
6,596 Expert 4TB
Sheesh!

I was doing research on using batch files as drop targets when I came across a python discussion thread on this site with the same topic. I thought I would share what I had learned (the hard way), but I could find no way to reply to that thread (even after registering!).

Anyway, wrapping the python script in a batch file is a good idea, but I believe the problem the python programmer was encountering was how Windows automatically sets the working directory when passing a file via "drop target".

So the answer was actually in the third post of that thread, but nobody called attention to the fact it would be necessary to change to the directory where the necessary files exist.

Since Windows does provide parameter 0 (the complete pathname of the batch file), you can do something like this (in Windows XP, i.e. with command extensions):

REM Lame way to ensure we are in the same directory as batch file
%~d0
cd %~p0

Where the first line simply evaluates to the drive letter and the second line evaluates the path. When processed by the command shell the commands might look like this:

c:
cd bin\scripts\test

Hopefully you get the idea. This sets the working directory to the same as directory as where the batch file resides. You could change this to explicitly set the directory to whatever you want.

Maybe you found all this out, but I didn't see any wrap up mail so I thought I would post.

Well, if this doesn't help the original poster, maybe it will help somebody else who ends up beating their head into the wall over this completely ridiculous, unintuitive behavior.
Thank you so much for posting. Could you please mention the title of the previous thread and or author? Drop in again sometime with more help for others or for help for your self. Regards,
Barton - python forum moderator
Nov 3 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Shufen | last post by:
Hi, Can someone please advice me on the differences between this: #!/usr/bin/env python and these: #!/usr/local/bin/python or #!/usr/bin/python? I know the first one locates the Python...
2
by: adityabhambri | last post by:
HI guys, I am trying to automate some project work which the accounting dept of the company uses. They have to go through multiple steps to achieve the final goal. Is there some way that I can use...
8
by: Ben Sizer | last post by:
I'd like to be able to drag a file onto a Python script in Windows Explorer, or send that file to the script via the Send To context-menu option, so I can then process that file via sys.argc. ...
20
by: Ramdas | last post by:
How do I add users using Python scripts on a Linux machine? Someone has a script?
0
by: P. Adhia | last post by:
Hello, I was wondering if anyone is successfully using using Python(2.5)+DB2+pydb2. I get an error in all situations. It seems that this problem might be limited to python 2.5. A quick Google...
0
by: davidj411 | last post by:
when does is make sense to use a ASP style Page (.psp) over a Python- based CGI script with IIS. ? http://support.microsoft.com/kb/276494 ASP requires registering the python engine. which...
0
by: chitras1984 | last post by:
Hi Could anyone help to get the log message using the python script And to stop the commit when the log message is empty Thanks Chitra
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.