?
Solved

How to get the long file name in bat file?

Posted on 2003-03-06
4
Medium Priority
?
326 Views
Last Modified: 2013-12-28
I am trying to add a new action to the association/file types in windows and I am calling a bat file for that action,but %1 parameter which I am referring inside the bat file is giving only the DOS file name ( the one with tilde symbol) instead of long file name.Is there any work around to get the long file name??

As I mentioned,I am attaching this bat file as a action command for a particular file type so when I am right clicking on those type I get that action.So I don't really pass this file name directly rather windows explorer does this.

Actually what I am doing is invoking a URL with this file name as a parameter and the url is a CGI script which manipulates the file at the server.

my bat file has something like this
start http://myserver:8100/rep/filegen?"%1"

Everything works but I get the DOS name instead of long name...Any clues??
Thanks
0
Comment
Question by:itmenon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:pbarrette
ID: 8094555
Hi itmenon,

This is what I tested on Win98. I created my own association for .PB files using the following for "Open Program With...":
C:\TEMP\PATHS.BAT "%1"

Then, I created the "C:\TEMP\PATHS.BAT" file which consists of the following:
:: -----PATHS.BAT------
@ECHO OFF
SET FILEPATH=
CD %1\..
DIR /B %1 > C:\TEMP\FILEPATH.TXT

ECHO @PROMPT SET FILEPATH=>C:\TEMP\TEMP1.BAT
TYPE C:\TEMP\FILEPATH.TXT >> C:\TEMP\TEMP1.BAT
ECHO @PROMPT $H >> C:\TEMP\TEMP1.BAT
command /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT
CALL C:\TEMP\TEMP2.BAT > NUL

DEL C:\TEMP\FILEPATH.TXT
DEL C:\TEMP\TEMP1.BAT
DEL C:\TEMP\TEMP2.BAT

START IEXPLORE "http://www.google.com/search?q=%%22%FILEPATH%%%22"
:: -----PATHS.BAT------

I tested this against a file called:
"This is a long filename.pb"

When I double-click the file, it opens a google page with the following URL:
http://www.google.com/search?q=%22This%20is%20a%20long%20filename.pb%22

So I'm having no problems with Win98 passing the longname to my batchfile.

Hope this helps,
pb
0
 

Author Comment

by:itmenon
ID: 8102802
Hi pb,

When I am running paths.bat file gets following messages::
Bad command or file name
Out of environment space
Bad command or file name

Bat file is failing on this step ::
command /C C:\TEMP\TEMP1.BAT >> C:\TEMP\TEMP2.BAT
it is giving me ::Bad command or file name.

Any idea??

Thanks
0
 
LVL 10

Accepted Solution

by:
pbarrette earned 120 total points
ID: 8103727
Hi itmenon,

I forgot to mention that it will return 1 or 2 instances of "Bad command or filename", but it still works fine.

This is because the TEMP1.BAT file contains lines which are run as commands, but are not actual commands. It is used only to get the filename into a variable.

If you are getting an "Out of environment space" error, then you need to be sure that you are running the batchfile in Win9x. It will not work as written in NT/2K/XP. To make it work in those OS's, you need to change the "COMMAND /C" to "CMD /C".

If none of those things helps, then you may need to change the "START IEXPLORE" to "START C:\PROGRA~1\INTERN~1\IEXPLORE.EXE"

pb
0
 

Author Comment

by:itmenon
ID: 8111866
Perfect on Win98!!!

I had to increase the environment space..!!!

thanks
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question