Computing.Net > Forums > Programming > Long to Short Filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Long to Short Filename

Reply to Message Icon

Name: Urkle10
Date: February 23, 2004 at 20:38:34 Pacific
OS: Windows 2000
CPU/Ram: PIII 600 / 256 MB
Comment:

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.dat

Any help would be greatly appreciated!

- Urkle10




Sponsored Link
Ads by Google

Response Number 1
Name: Dr. Nick
Date: February 24, 2004 at 00:29:25 Pacific
Reply:

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?


0

Response Number 2
Name: Urkle10
Date: February 24, 2004 at 08:20:19 Pacific
Reply:

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 %~s1

Where 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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Long to Short Filename

batch script to replace filenames h www.computing.net/answers/programming/batch-script-to-replace-filenames-h/16301.html

Long filenames not supported proble www.computing.net/answers/programming/long-filenames-not-supported-proble/13052.html

batch script to parse filenames www.computing.net/answers/programming/batch-script-to-parse-filenames/15286.html