Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

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

- - - - -

  • Please log in to reply
27 replies to this topic

#26
MDGx

MDGx

    98SE2ME + 98MP10

  • Super Moderator
  • 2,678 posts
  • OS:none specified
  • Country: Country Flag
FYI...

LFNFOR is an internal batch command, and enables the use of LFNs strictly for the "FOR" batch command.
Wikipedia:
http://en.wikipedia....iki/COMMAND.COM
BATutil (with practical examples):
http://users.cyberci...RIOUS.HTM#jerry

Can be enabled system-wide every time upon (re)boot [no matter if it is native DOS mode or Windows 9x GUI mode or DOS box/console mode] by adding a line for it in AUTOEXEC.BAT:

LFNFOR ON

Windows ME users must add it in each separate MS-DOS Configuration File (PIF) shortcut Properties [which makes it available only for that particular DOS box/session/console], since MS removed autoexec.bat + config.sys (boot files) support from WinME.
If one cares to restore native DOS mode, autoexec.bat + config.sys support in WinME, please use 1 of these free tools:
http://www.mdgx.com/dos.htm#ME

HTH


How to remove advertisement from MSFN

#27
Queue

Queue

    Member

  • Member
  • PipPip
  • 164 posts
I finally took the time to test things out on WinXP and had to make some adjustments. I also added drag&drop support. The script is a bit more skewed towards only working for .asm files, as that's the purpose my batch file was built for.
@echo off
:: Set project name
goto chk
:pth
if "%NAME%"=="" goto use
if not exist "%NAME%.asm" goto use

:: Set compiler paths
path ;
path "D:\My Documents\Development\masm32\include"
set INCLUDE=%PATH%
path ;
path "C:\Program Files\Microsoft Visual C++ 6.0 Standard Edition\VC98\LIB"
set LIB=%PATH%
path ;
path "C:\Program Files\Microsoft Visual C++ 6.0 Standard Edition\VC98\BIN"

:: =======================================================================================

:: Put stuff to do to your target file in place of the following three placeholder lines
cd
echo %NAME%
goto fin

:: .......................................................................................

:chk
if ?%1?==?? goto use
if ?%1?==?]?? goto pre
if ?%1?==?[?? goto prs
if ?%2?==?? if exist %1 goto ver

cls
path ;
set NAME=%1
if ?%2?==?? goto pth
set NAME=%NAME% %2
if ?%3?==?? goto pth
set NAME=%NAME% %3
if ?%4?==?? goto pth
set NAME=%NAME% %4
if ?%5?==?? goto pth
set NAME=%NAME% %5
if ?%6?==?? goto pth
set NAME=%NAME% %6
if ?%7?==?? goto pth
set NAME=%NAME% %7
if ?%8?==?? goto pth
set NAME=%NAME% %8
if ?%9?==?? goto pth
set NAME=%NAME% %9
goto pth

:ver
if "%~n1"=="~n1" goto w9x
path ;
set NAME=%~n1
if "%NAME%"=="" goto use
if not exist "%NAME%.asm" cd /D "%~dp1"
goto pth

:w9x
rem > "%TEMP%.\BUILDTMP.BAT"
if not exist "%TEMP%.\BUILDTMP.BAT" goto use
lfnfor on
for %%A in (%1*) do if not exist %1.* move /Y "%TEMP%.\BUILDTMP.BAT" "%%A.tmp"
for %%A in (%1*) do %COMSPEC% /C for %%B in ("%%A*") do call %0 ]? %%B
for %%A in (%1*) do if exist "%%A.tmp" del "%%A.tmp"
if not exist "%TEMP%.\BUILDTMP.BAT" goto use
echo %1| choice /N /C:ABCDEFGHIJKLMNOPQRSTUVWXYZ:\ | set _=
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [) do if errorlevel H%%A set _=%%A
if ?%_%?==?[? set _=
set NAME=
call "%TEMP%.\BUILDTMP.BAT" %0
del "%TEMP%.\BUILDTMP.BAT"
if "%NAME%"=="" goto use
if not exist "%NAME%.asm" cd %1\..
if not exist "%NAME%.asm" if not ?%_%?==?? %_%:
goto pth

:: .......................................................................................

:pre
cls
shift
shift
if ?%0?==?? goto end
if ?%1?==?? goto ch0
if ?%2?==?? goto ch1
if ?%3?==?? goto ch2
if ?%4?==?? goto ch3
if ?%5?==?? goto ch4
if ?%6?==?? goto ch5
if ?%7?==?? goto ch6
if ?%8?==?? goto ch7
if ?%9?==?? goto ch8
echo ;| choice /S /C:?%0*%1*%2*%3*%4*%5*%6*%7*%8*%9; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch8
echo ;| choice /S /C:?%0*%1*%2*%3*%4*%5*%6*%7*%8; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch7
echo ;| choice /S /C:?%0*%1*%2*%3*%4*%5*%6*%7; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch6
echo ;| choice /S /C:?%0*%1*%2*%3*%4*%5*%6; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch5
echo ;| choice /S /C:?%0*%1*%2*%3*%4*%5; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch4
echo ;| choice /S /C:?%0*%1*%2*%3*%4; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch3
echo ;| choice /S /C:?%0*%1*%2*%3; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch2
echo ;| choice /S /C:?%0*%1*%2; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch1
echo ;| choice /S /C:?%0*%1; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end
:ch0
echo ;| choice /S /C:?%0; %%1 > "%TEMP%.\BUILDTMP.BAT"
goto end

:: .......................................................................................

:prs
path ;
:sla
set NAME=
:chr
shift
if ?%0?==?? goto end
if ?%0?==?]?? goto end
if ?%0?==?\? goto sla
if ?%0?==?[?? goto sla
if ?%0?==?.? goto per
if ?%0?==?*? goto ast
set NAME=%NAME%%0
goto chr
:per
shift
if ?%0?==?? goto end
if ?%0?==?]?? goto end
if ?%0?==?\? goto sla
if ?%0?==?[?? goto sla
goto per
:ast
set NAME=%NAME% 
goto chr

:: .......................................................................................

:use
echo Usage: BUILDASM.BAT Project Name
echo    or: BUILDASM.BAT X:\FOLDER~1\FILENAME.ASM
echo    or: BUILDASM.BAT "X:\Long Folder Name\Long File Name.asm"

:fin
echo Press any key to exit . . .
pause | rem | cls

:end
Unfortunately, cmd.exe is pretty dumb about nesting commands on a single line. For example, pause | cls works fine with command.com, but with cmd.exe, the cls clears the screen during the pause instead of after it, hence why I had to do pause | rem | cls instead. cmd.exe also chokes on path ; | path "drive:\real path" (a nice space saver), so I had to spread out the '':: Set compiler paths'' section a little.

In this version I removed any nul redirections; I read that handles opened to devices (nul is a device) aren't closed properly the way file handles are. Whether it's true or not, finding redirection replacements for nul wasn't hard.

Queue

Edited by Queue, 15 May 2010 - 12:24 PM.


#28
loblo

loblo

    Oldbie

  • Member
  • PipPipPipPipPip
  • 758 posts
  • OS:ME
  • Country: Country Flag

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.

 

After unsuccessfully trying to do lots of things in the bat files themselves I ended replacing the bat and pif drophandlers in the registry by the windows script host drophandler.

 

From:

 

[HKEY_CLASSES_ROOT\batfile\shellex\DropHandler]
@ = "{86C86720-42A0-1069-A2E8-08002B30309D}"

[HKEY_CLASSES_ROOT\piffile\shellex\DropHandler]
@ = "{86C86720-42A0-1069-A2E8-08002B30309D}"

 

To:

 

[HKEY_CLASSES_ROOT\batfile\shellex\DropHandler]
@ = "{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\piffile\shellex\DropHandler]
@ = "{60254CA5-953B-11CF-8C96-00AA00B8708C}"

 

 

Works nicely, now the output of my batch files using %1 arguments is always LFN. However, this would presumably break working with 16bit dos programs that can't handle LFNs but in this case it would be easy to temporarily toggle those values with a couple of registry files.

 

 And btw processing multiple files using forfiles.exe from the Win98 resource kit and bat files always results in LFN output regardless of which drop handler is being used.


Edited by loblo, 16 September 2014 - 08:31 AM.

  • dencorso likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN