473,396 Members | 1,968 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.

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 4010
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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...
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,...

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.