Jump to content

Passing an LFN to a .BAT script through Send To function or file assoc


Sfor

Recommended Posts

I've been trying to feed a .BAT script with Long File Names using Send To folder or file association. For some reason Windows 98 sends just the short names, always. Is there a way to force an LFN to be passed through command line parameters.

Link to comment
Share on other sites


Do you have access to the target directory? First thing which comes in my mind is using tar or zip or maybe even lfnbk to preserve the long filename, and restore it on the target position.

Is there a way to force an LFN to be passed through command line parameters.
You did put quotes around the filename, didn't you?
Link to comment
Share on other sites

Do you have access to the target directory? First thing which comes in my mind is using tar or zip or maybe even lfnbk to preserve the long filename, and restore it on the target position.

Is there a way to force an LFN to be passed through command line parameters.
You did put quotes around the filename, didn't you?

The problem is not related to copying files. What I'm trying to do is to run a .BAT file with a LFN as a command line parameter.

The Send To option using /Windows/SendTo folder does not seem to care for the command line arguments provided in a .PIF file. The result is the same in case of both .BAT and .EXE.

Edited by Sfor
Link to comment
Share on other sites

Maybe you can use the BAT to find the actual long file name by using one of the most "obscure" commands ever included in 9x:

LFNFOR:

http://www.nukesoft.co.uk/msdos/command.php?id=60

http://www.robvanderwoude.com/w95lfnfor.php

jaclaz

I've found no way to get the LFN from the short name with the use of FOR command.

If the searched file mask refers to a short name, the output is also a short file name.

FOR %%A IN (%1) DO ECHO %%A

The %%A will be a short file name if the %1 is a short file name.

Link to comment
Share on other sites

The %%A will be a short file name if the %1 is a short file name.

Hmmm, maybe you need to use an intermediate DIR command, but then you will need a temporary file. :unsure:

http://www.ericphelps.com/batch/lists/filelist.htm

What about trying the 9x enhanced command processor?

http://www.boot-land.net/forums/?showtopic=2392

It may be possible to avoid the temporary file.

I haven't a 9x machine/VM handy to further help you, but maybe this helps (haven't tested it, nor even understood it):

http://users.cybercity.dk/~bse26236/batutil/help/how/VARIOUS.HTM

(search for LFNFOR on the page)

I'll see if I can find some of the good ol' LFN utilities, there may be one capable of doing this "conversion".

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

The whole thing gets more and more complicated. So, I've decided to write own utility to do the job.

After a brief test I've confirmed the LFN DOS extension makes possible for a DOS application to find a LFN while searching for a short file name. So, using a "proxy" DOS application I shoud be able to convert the short filename to the LFN one.

Link to comment
Share on other sites

I was able to get the desired result through the file association. But, there are several conditions to be met.

Apparently, Windows does check the type of the target application. If the type is unknown, or it is a 16 bit application the file name is sent a a short one. So, it is necesary to direct the output to a Win32 application. The full file path to the EXE file is necesary as well. In order to meet these demands I've used the C:\WINDOWS\COMMANDS\START.EXE application. As command line parameters I've used something like that: c:\xxx\batfile.bat "%1"

But, the same trick does not work in the Send To menu.

Edited by Sfor
Link to comment
Share on other sites

A .pif file is sent SFN.

A link to Start.exe creates a .lnk file -> passed a LFN.

Also links to vbscripts (.vbs files) are passed LFN's.

If vbscript is available on the target create a link to a .vbs file.

W98 will pass LFN always..even as a .lnk file in the sendto folder.

Simple vbscript to RUN your bat - save as c:\temp\tmp.vbs -

WScript.CreateObject("WScript.Shell").Run "C:\TEMP\TMP.BAT " & WScript.Arguments(0), 1, FALSE

For a test - c:\temp\tmp.bat looks like this:

@ECHO OFF
ECHO %1 %2 %3 %4 %5 %6 %7 %8 %9

Note tmp.bat still sees the command line as separate pieces when spaces are present in the path/filename.

Link to comment
Share on other sites

Note tmp.bat still sees the command line as separate pieces when spaces are present in the path/filename.

So to avoid that I added quadruple quote marks.:

WScript.CreateObject("WScript.Shell").Run "C:\TEMP\TMP.BAT """ & WScript.Arguments(0) & """", 1, FALSE

Note that through file association, it will starts one instance of vbs/bat (or whatever you use) file for each file selected in explorer. This forbid batch processsing in a single process and will pop up a hell of lot of dos prompts if you select many files at once.

So this is a solution to use with one file at a time only, no matter the way you cut it.

The ONLY solution for that (I'v been searching that very deeply) is to use my Context Menu Customizer Hta (coming with a special "Launch Script" feature) together with (or using separately if you don't want to use my Context Menu Customizer) Fast Explorer.

Both apps are freeware.

HTH

Edited by Fredledingue
Link to comment
Share on other sites

So, I think I've worked out a rather horrific mechanism for file associated .BAT files to parse out a passed file name with proper case. I haven't had a chance to text on anything except Win98SE, but I included what I think will work as a Windows version test. This specific example is to parse out the file name without extension or path, so would need to be adapted for your own needs. I happened to make this earlier this afternoon for a fairly automated system I set up to compile assembly code (in .asm files); I wanted to simply right click an .asm file, select compile, and have a batch file handle everything else.

To use this, the file association needs to be

BUILDASM.BAT /auto %1


@echo off
goto chk
:pth

echo %NAME%
goto fin

:chk
if ?%1?==?? goto use
if ?%1?==?/auto? goto :ver
if ?%1?==?-auto? goto :prs

cls
set NAME=%1
:add
shift
if ?%1?==?? goto pth
set NAME=%NAME% %1
goto add

:ver
if ?%2?==?? goto use
if ?%~n2?==?~n2? goto w9x
set NAME=%~n2
goto pth

:w9x
lfnfor on
for %%A in ("%2*") do set NAME=%%A
if ?%NAME%?==?? goto fin
echo ;| choice /S /T;,1 /C:;%NAME%; BUILDASM.BAT -auto > "%TEMP%.\temp.bat"
set NAME=
call "%TEMP%.\temp.bat"
del "%TEMP%.\temp.bat"
goto pth

:prs
shift
if ?%1?==?? goto end
if ?%1?==?]?? goto end
if ?%1?==?.? goto per
if ?%1?==?\? goto sla
set NAME=%NAME%%1
goto prs
:per
shift
if ?%1?==?? goto end
if ?%1?==?\? goto sla
goto per
:sla
set NAME=
goto prs

:use
echo Usage: BUILDASM.BAT Project Name

:fin
echo Press any key to exit . . .
pause > nul
cls
:end

I left out basically all the code that was specific to my project; where it says ''echo %NAME%'' near the top is where stuff specific to what I was doing would be.

If you want to test this, throw it in a .BAT file, and run it like:

BUILDASM.BAT /auto C:\real_dir_name\real_file_name.txt

Actually, I'm not sure what it'll do if the target file doesn't exist.

I'd love to hear how it works on an XP or Vista/7 machine, since I included a %~n1 test.

Edit - I guess there are issues with long file names and files with spaces in their names unfortunately; my test case was an 8.3 file name, and the for loop with lfnfor on worked just because the file name was simple enough. Still, might be useful to someone.

Edit 2 - Hah, it's basically a buffer size problem. The choice command, if the ''choices'' string is too long, it overwrites the ''question'' string, which is what runs the batch file. So you're limited both by the size of the path for the batch file, and the size of the path for the target file. D'oh.

Edit 3 - Also, it can hit a limit for command line argument count if the size of the path for the target file is too long. I've revised the code above with any improvements I came up with, and it still works just peachy for what I built it for. So, at least on Win9x, its shortfalls are it can't handle spaces in the file name and it can't handle a path name for the target file that's too long. The changed version requires the .BAT file to be named BUILDASM.BAT unless you change the self-reference in the :w9x section.

Queue

Edited by Queue
Link to comment
Share on other sites

It's really not the same thing because it's achieved in about as different of a way as possible. Honestly, I haven't even figured out how some of those examples work (the author appears to abuse formatting a lot so comments are mingled in with commands and he has a fondness for using debug). Good link though.

Queue

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...