Rob van der Woude's Scripting Pages

The FOR command and VFAT/FAT32 long file names:

LFNFOR

Try this in Windows 95/98, in a directory that contains some files with long file names (C:\WINDOWS\DESKTOP ?):

@ECHO OFF
REM The next 3 lines assume an English MS-DOS 7.* version
SET LFNFOR=OFF
LFNFOR | FIND "ON" > NUL
IF NOT ERRORLEVEL 1 SET LFNFOR=ON
 
LFNFOR OFF
FOR %%A IN (*.*) DO ECHO %%A
PAUSE

LFNFOR ON
FOR %%A IN (*.*) DO ECHO %%A

LFNFOR %LFNFOR%
Note: If you do not have an English Windows 95/98 version, change the search string ("ON") in the command LFNFOR | FIND /I "ON" > NUL accordingly.
Find out what search string you need by typing LFNFOR /?

When you execute this batch file, you will see a list of "8.3" file names first (before the PAUSE command, LFNFOR is OFF). After pressing the any key (PAUSE) the long file names for those same files will be displayed (LFNFOR is ON).

This shows exactly what LFNFOR does: tell MS-DOS 7.*'s FOR command whether it should use "8.3" or long file names.

Make sure your batch files are aware of the actual LFNFOR state when using FOR commands on file names.

Bug Alert: With LFNFOR set to ON, only the first file name will be shown with its full path!
See for yourself. Type:
LFNFOR ON
FOR %%A IN (C:\WINDOWS\*.BMP) DO ECHO %%A

Compare this with the output of:
LFNFOR OFF
FOR %%A IN (C:\WINDOWS\*.BMP) DO ECHO %%A

page last modified: 2014-10-02; loaded in 0.0014 seconds