Computing: Computer Administration

Using long file names on FreeDOS.

On DOS operating systems, a full filename is made of two parts:

  1. the file name, between 1 and a maximum of 8 ASCII characters (space not permitted);
  2. an optional file extension, between 1 and a maximum of 3 ASCII characters (space not permitted), separated from the file name by a dot (.).

Note: This is also true for full directory names (that normally do not, but may, include an extension).

Even though this 8-character naming system is not always user-friendly (you'll have to name a file that you would want to name "palindrome.asm" to something like "palindro.asm" or "palndrme.asm", for example), you normally don't need support for long file names on DOS. There are, however, 2 situations, where being able to handle files with names of more than 8 characters makes life easier, or even is necessary:

One of the important points to be aware of is that, independently if there is or is not support for long file names, DOS internally handles all files with a name of a maximum of 8 characters. Files with longer names (for example created on Windows), are shortened (transformation of long file names to DOS short file names). The DOS short file name is (normally) made of the first 6 characters of the real file name, followed by a tilde (~) and a number. On the other hand, when creating a new file with a long name, the short file name is obtained by truncating the real name to 8 characters. Also, DOS filenames are normally all uppercase (what is, however, not important, because on DOS, as on Windows, file names are case-insensitive).

In the following examples, my floppy diskette contains a folder with name "longfilename_folder" (that on DOS will be named "LONGFI~1"), that contains the files "longfilename_file2.txt" and "longfilename_file3.txt" (called respectively "LONGFI~2.TXT" and LONGFI~3.TXT" on DOS). On DOS, this directory and its files are listed with their short file names, and we'll have to use the short file names to access them.

On the left screenshot below, the command cd longfilename_folder results in the error message CHDIR failed for 'longfilename_folder'; we have to use cd longfi~1 instead. Using the dir command to list the folder content, the two files with long names are listed with their 8-character DOS short name. The command copy longfilename_file2.txt longfilename_file4.txt fails with the error message Cannot copy 'longfilename_file4.txt' to itself. This might surprise. But, remember what we said above: DOS considers names of 8 characters only, what for both files results in a short file name of "LONGFILE.TXT", thus in a copy command with destination = source. On the other hand, the command copy longfi~2.txt longfilename_file4.txt succeeds. For existing files, we have to use the DOS short name (with the "~" character), new file names are truncated to 8 characters, thus DOS can copy the file longfilename_file4, the resulting file name being called "LONGFILE.TXT", as you can see on the screenshot on the right. Surprisingly, the new file can be accessed with either its short or its long file name (type command on the screenshot). This means that, even without a long file name driver, the FreeDOS command interpreter has some LFN support.

Long file names on FreeDOS: File copy without LFN driver [1]
Long file names on FreeDOS: FreeCOM long file name support without LFN driver

The following screenshot shows the result of the command copy longfi~3.txt longfilename_file5.txt. This corresponds to copy the existing file "longfilename_file3.txt" to a file with short name "LONGFILE.TXT". This file already exists (in fact it's our file "longfilename_file4.txt"), thus DOS asks if it should be overwritten.

Long file names on FreeDOS: FreeCOM long file name support without LFN driver [2]

We could work this way, but installing a long file name driver will make life lots easier. The FreeDOS installation files include the driver DOSLFN, that works fine for me. There is another driver, called LFNDOS available out there on the Internet; on my system its usage resulted in an abnormal program termination. Concerning LFNTOOLS, utilities to manipulate files with long names, they also did not work on my system; anyway, they are not needed. With DOSLFN installed, FreeCOM will fully support long file names.

If you want long file name support all the time, you can load the driver in your FDCONFIG.SYS file. If you want to install it only if needed, you can add the choice to load it or not into FDAUTO.BAT. Here are the corresponding commands in my FDAUTO.BAT:
    :AskLFN
    choice /C:01 /N /T:0,5 Choose long file name driver: 0=none, 1=DOSLFN, (default=0)?
    if errorlevel 2 goto InitDOSLfn
    goto Final
    :InitDosLfn
    lh doslfn.com
    set DIRCMD=/P /OGN /Y /LFN
    goto Final

It is supposed that DOSLFN.COM is located in a directory that is in your PATH. Placed into the FreeDOS "bin" directory during installation of the OS, this should normally be the case.

Important to know, that in order to list long file names with the standard dir command, you'll have to add the option /LFN to your DIR command string (DIRCMD environment variable).

The screenshot below has been taken on my system with DOSLFN installed and the /LFN option added to DIRCMD. You can see that now the command cd longfilename_folder works correctly, and that the dir command now lists the real file names (last column of the directory listing).

Long file names on FreeDOS: Directory listing with DOSLFN driver installed

The following screenshot shows how the copy command works with DOSLFN installed. The command copy longfilename_file1.txt long_filename_file1.txt works correctly and creates a file with long name "long_filename_file1.txt". Note, that in this case the DOS short file name is not obtained by truncating the long name to 8 characters, but by building a file name using the "~" character ("LONG_F~1.TXT"). On the other hand, commands like copy longfilename_file1.txt longfilename_file6.txt or copy longfilename_file1.txt longfile_file1.txt are not permitted. Simply because the short DOS file name of the destination file is the same as the short name of the source file!

Long file names on FreeDOS: File copy with DOSLFN driver installed

Deleting a file with a long name is no problem. Renaming a such file is subjected to the same restriction as when copying a file. The somewhat weird error message rename: permission denied simply means that there already is a file that has the same short DOS file name as the destination file of the rename command.

Long file names on FreeDOS: File delete and rename with DOSLFN driver installed

Similar considerations apply to the commands mkdir and rmdir.

You should never use files with long file names with programs that do not support LFN!. This may, in fact, lead to truly unwanted results. An example is FreeDOS Edit, that if a long file name is specified, truncates the file name to 8 characters. Consider the following command: edit longfilename_file2.txt. What do you think that happens if you change the content of the file opened in the editor? It will not be "longfilename_file2.txt", but "LONGFILE.TXT" that will be changed! And if this file already existed (as it is the case here), you will modify the content of the wrong file (if the files have all different content, you will notice it, but for similar content...).

I like to play around with batch files, and so I wrote lfnedit.bat, that is a work-around that makes it possible to correctly edit files with long names in FreeDOS Edit by making the editor open a temporary file with an 8-character name. Here are the commands of my batch file:
    @echo off
    if "%1"=="" goto End
    set lfnname=%1
    set tempname=c:\temp\lfnedit.tmp
    if exist %tempname% del %tempname%
    copy %lfnname% %tempname%
    edit %tempname%
    copy %tempname% %lfnname%
    del %tempname%
    set lfnname=
    set tempname=
    :End

This is playing around, not more. The real solution of the issue is, of course, to use an editor with LFN support. There are several available, I think. A good choice would be FTE, that compared to the default FreeDOS editor, has another important advantage: It can handle those large files, that FreeDOS Edit doesn't open, saying "File too large for this version of EDIT". You can download FTE for free from the Sourceforge website.

Long file names on FreeDOS: FTE - a text editor with LFN (and large files) support

To note that DOSLFN also supports file names containing spaces. As in Windows Command Prompt, you'll have to enclose the file name in double quotes (") when using such file names in DOS commands like, for example, copy.

I think that it is worse to mention that the famous file manager Norton Commander fully supports long file names, if you have loaded the DOSLFN driver...

Conclusion: Using long file names on DOS is a rather complex affair, and you should always use regular DOS file names, unless the support for long file names is required by the software that you are using. If, for example, you run PythonD, it is mandatory to load DOSLFN; otherwise the program will not find all files that it needs, in particular the libraries to be imported.


If you find this text helpful, please, support me and this website by signing my guestbook.