Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
OS: Windows 2000
I'm using a program that accepts the command line argument -file_name and opens the file specified in the argument immediately following. Here is an example:
program.exe -file_name input.dat
It would open input.dat where input.dat is in the same folder as program.exe. I would like to be able to double-click a file in Windows Explorer and have it be opened by the program. I thought it would be a simple matter of modifying the DAT association in the Windows Explorer settings to run:
"C:\Program Files\prog\program.exe" -file_name %1
However, the %1 is replaced with the full path of the DAT file that is double-clicked. If this full path contains any spaces, program.exe complains that it cannot open the file because the arguments passed to program.exe are separated by spaces. For example:
program.exe -file_name C:\My Folder\input.dat
The program would try to open "C:\My" and fail. However, if the short filename format of the above path is used intead, then the program works fine. Here is the short format:
program.exe -filename c:\myfold~1\input.dat
Is there any way to write a batch file that accepts a long filename and converts it into its short format and runs the exe properly? For example, convert:
program.bat C:\My Folder\input.dat
OR
program.bat "C:\My Folder\input.dat"
TO
program.exe -file_name c:\myfold~1\input.datAny help would be greatly appreciated!
- Urkle10

If you are calling it from the command prompt or a batch file you can use the new % values found here or by typing "CALL /?" into the command prompt.
In your example, you'll want to use it like this in your batch file: "program.exe %~s1".
Is that what you're looking for?

That is exaclty what I was looking for, thank you. This is what I used in my program.bat file:
@echo off
c:\progra~1\prog\program.exe %~s1Where in the Windows Explorer file association settings, I told it to call:
"C:\Program Files\prog\program.bat" -file_name "%1"
The double quotation marks around the %1 were important as it told the batch file that it was all one argument.
I appreciate the help! Thanks!
Urkle10

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |