Sfor Posted April 30, 2010 Posted April 30, 2010 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.
Mijzelf Posted April 30, 2010 Posted April 30, 2010 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?
jaclaz Posted April 30, 2010 Posted April 30, 2010 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=60http://www.robvanderwoude.com/w95lfnfor.php jaclaz
Sfor Posted April 30, 2010 Author Posted April 30, 2010 (edited) 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 April 30, 2010 by Sfor
Sfor Posted April 30, 2010 Author Posted April 30, 2010 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=60http://www.robvanderwoude.com/w95lfnfor.php jaclazI'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 %%AThe %%A will be a short file name if the %1 is a short file name.
jaclaz Posted April 30, 2010 Posted April 30, 2010 (edited) 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. http://www.ericphelps.com/batch/lists/filelist.htmWhat about trying the 9x enhanced command processor?http://www.boot-land.net/forums/?showtopic=2392It 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 April 30, 2010 by jaclaz
Sfor Posted April 30, 2010 Author Posted April 30, 2010 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.
jaclaz Posted April 30, 2010 Posted April 30, 2010 Just in case:VARSET:http://home.mnet-online.de/horst.muc/div.htmshould do the trick.jaclaz
Fredledingue Posted April 30, 2010 Posted April 30, 2010 I don't understand: On a Send To folder or file association, the parameter for the file path iis %1 or "%1" (with quotes) or again %1 %. One of these variant should give the LFN.My Context Menu Customizer Hta or Fast Explorer might be of interrest, thought not directly offering a solution to this very problem.
Sfor Posted May 1, 2010 Author Posted May 1, 2010 (edited) 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 May 1, 2010 by Sfor
sleffing Posted May 2, 2010 Posted May 2, 2010 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, FALSEFor a test - c:\temp\tmp.bat looks like this:@ECHO OFFECHO %1 %2 %3 %4 %5 %6 %7 %8 %9Note tmp.bat still sees the command line as separate pieces when spaces are present in the path/filename.
Fredledingue Posted May 5, 2010 Posted May 5, 2010 (edited) 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, FALSENote 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 May 5, 2010 by Fredledingue
Queue Posted May 6, 2010 Posted May 6, 2010 (edited) 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 beBUILDASM.BAT /auto %1@echo offgoto chk:pthecho %NAME%goto fin:chkif ?%1?==?? goto useif ?%1?==?/auto? goto :verif ?%1?==?-auto? goto :prsclsset NAME=%1:addshiftif ?%1?==?? goto pthset NAME=%NAME% %1goto add:verif ?%2?==?? goto useif ?%~n2?==?~n2? goto w9xset NAME=%~n2goto pth:w9xlfnfor onfor %%A in ("%2*") do set NAME=%%Aif ?%NAME%?==?? goto finecho ;| choice /S /T;,1 /C:;%NAME%; BUILDASM.BAT -auto > "%TEMP%.\temp.bat"set NAME=call "%TEMP%.\temp.bat"del "%TEMP%.\temp.bat"goto pth:prsshiftif ?%1?==?? goto endif ?%1?==?]?? goto endif ?%1?==?.? goto perif ?%1?==?\? goto slaset NAME=%NAME%%1goto prs:pershiftif ?%1?==?? goto endif ?%1?==?\? goto slagoto per:slaset NAME=goto prs:useecho Usage: BUILDASM.BAT Project Name:finecho Press any key to exit . . .pause > nulcls:endI 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.txtActually, 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 May 6, 2010 by Queue
jaclaz Posted May 6, 2010 Posted May 6, 2010 @QueueIsn't it the same thing as this?:http://users.cybercity.dk/~bse26236/batutil/help/how/VARIOUS.HTM#jerryjaclaz
Queue Posted May 6, 2010 Posted May 6, 2010 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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now