Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to get the long file name in bat file?

Posted on 2003-03-06
4
Medium Priority
?
331 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension . This reminded me of questions that come up here at EE along the lines of, "How can I tell the type of file from its cont…
It is a real story and is one of my scariest tech experiences. Most users think that IT experts like us know how to fix all computer problems. However, if there is a time constraint and you MUST not fail the task or you will lose your job, a simple …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

577 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