469,647 Members | 1,711 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

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 3841
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

Post your reply

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

Similar topics

2 posts views Thread by Shufen | last post: by
2 posts views Thread by adityabhambri | last post: by
8 posts views Thread by Ben Sizer | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.