DOSLFNBK v 2.7 - Backs up/restores Win95 long filenames in DOS

Copyright (c) 1995, 2002 D.J. Murdoch.


  1. Syntax
  2. Description
  3. Details
  4. Memory Limitations
  5. Safety
  6. Recovery from Total Disk Failure
  7. Licensing
  8. Release History
  9. Acknowledgments


DOSLFNBK drive:directory [options]

will back up all the long filename records in the named directory and subdirectories of it to a file.


Back up all filenames, not just LFNs and unusual attributes.
Automatically accept the safe default without prompting.
/f filename
Back up to this file (default BACKUP.LFN; default .LFN extension).
Force DOSLFNBK to go ahead without asking questions, even when it may be unsafe.
/from pathname
Restore names from this path.
Use high level disk access (backup only)
List contents of backup file.
No attributes: don't back up or restore attributes.
No full restore check.
No recursive: don't do subdirectories.
Don't restore times from LFN backup.
Always overwrite existing LFNs.
Go ahead if LFN damage is found.
Prompt before each filename restore (ignored during saves).
Quieter restore.
Restore from existing backup.
/s directory
Skip directory.
Verbose: give running status report.
/d filename
Write a detailed debugging log to filename.


For recovery from a total disk failure, see below.

To back up every long filename on the disk into BACKUP.LFN:

To restore just the Windows directory and subdirectories:
DOSLFNBK c:\windows /r

To restore just the root directory, but no subdirectories:
DOSLFNBK c:\ /r /nr

To backup everything except the MS Internet Explorer cache and history directories:
DOSLFNBK c:\ /s \progra~1\micros~1\cache /s \progra~1\micros~1\history

To backup the current directory and subdirectories:

To restore the "Program Files" directory name and its subdirectories, you need two runs:
DOSLFNBK c:\ /r /p /nr

On the second run, you'll be prompted for each name to restore; just say yes when you see "Program Files".

To see what filenames in the "Program Files" directory and its subdirectories are in the current BACKUP.LFN file:

To restore names from files that were originally in D:\OriginalDir (short name \ORIGIN~1) but which are now in E:\CurrentDir:
DOSLFNBK e:\CurrentDir /r /from \ORIGIN~1

To get a listing of every file on your disk, including attributes, sizes and times:
DOSLFNBK c:\ /all

Back to top


Microsoft's Windows 95 introduced long filenames (LFNs), and they are mostly compatible with old software. However, there are some problems. Old backup programs don't recognize LFNs, so they don't get properly backed up. Worse, the Win95 backup program didn't support a lot of common backup hardware (e.g. the Colorado Memory Systems tape drive using an accelerator card that I owned) and wouldn't run in DOS mode, so recovery from a catastrophic disk failure was really difficult.

To address this problem, Microsoft put a program called LFNBK on the Win95 CD ROM to back up your LFNs. However, it's very inconvenient to use. It requires changes to your Control Panel settings before and after use, and it works by stripping all the LFNs off your disk --- so you need to restore them again after you've done your backup to tape. It will only run after Win95 has booted, so again you've got big problems after a catastrophic disk failure.

If you've got a program that is completely incompatible with LFNs then you might want to use LFNBK, but for routine system backups it's too much of a pain.

I wrote DOSLFNBK to address these problems. It runs in any version of DOS that can see your disk, and can both backup and restore your files there. During backup, it makes no changes to the names, so you can routinely run it just before a tape backup and not have to undo the damage afterwards. It also allows partial backups and partial restores; LFNBK was an all-or-nothing affair.

The downside of DOSLFNBK is that it has to work on the disk below the file system level. This means that it needs to lock the disk to make sure no other programs are writing to the disk while it is running. This may cause errors in the other programs; I recommend shutting them down before running DOSLFNBK, or running it in a single-tasking DOS session.

Back to top


Contents of this section:

what DOSLFNBK does
When doing a backup, DOSLFNBK reads the directories on the disk and writes copies of all of the LFN records to the binary BACKUP.LFN file (or whatever file you specify with /f). If you use the /nr option, it will work only on the specified directory; otherwise, it saves those entries as well as everything in any subdirectory below it.
what is in the backup file
DOSLFNBK stores a full copy of the directory record for each backed up file. You can see this information by using the /l option to list the file. It also keeps a record of which version of DOSLFNBK was used to produce the backup, and what command line arguments were used. You can see this information by TYPEing the backup file, or using the /v option when reading it.
how to specify which directory to back up
Relative directory specifications are supported, and DOSLFNBK understands SUBST to some extent. (I believe it's possible with a complicated network of SUBST, JOIN, etc. to confuse it; don't do that!) The directory name itself won't be backed up or restored; only the files and subdirectories within it. There is no way to specify a subset of the files; you have to use the /p prompting option if you want this. The original drive letter is not stored in BACKUP.LFN, so you can use DOSLFNBK to save the long filenames on one drive, use a DOS utility to move them to another drive, and then restore the filenames there.
how to specify which directory to restore from
By default DOSFLBNK will restore to the same full path as was originally backed up. To restore to a different target directory, use the /from option. The name given in the /from option should be the original directory name fully specified in 8.3 format, with no drive letter. For example, if you back up E:\OriginalDir, you should restore using the option "/from \ORIGIN~1". If you forget the 8.3 form, use the /L option to list the backup file to see it.
existing long filenames and the /o option
DOSLFNBK will normally not overwrite an existing LFN with a different one; you should rename the file to its 8.3 alias before running if you want to restore an old name, or run with the /p option for individual prompting, or the /o option to force overwrites. These two options are mutually exclusive. Some DOS versions (e.g. Hebrew DOS) store special characters for short filenames in records that are identical to long filename records. To restore the true long filenames in these DOS versions, you *must* use either the /p or the /o option. Similarly, Win95 sometimes generates LFNs when you copy files with special characters (e.g. accented letters). If you have moved or manipulated these files in Win95, you'll need to overwrite these generated LFNs.
Win95 sometimes creates LFNs for files with special characters in the names, even if the name is otherwise pure 8.3 form. I suspect this is to allow compatibility across code pages: the LFN will use the Unicode character encoding, while the 8.3 record depends on the code page. DOSLFNBK will handle these properly for code page 437 (the standard US code page), but it may fail to restore some filenames containing special characters in other code pages, because it will think they are valid LFNs. Use /p or /o to force a restore of these names as well.
date information
Normally, DOSLFNBK will restore the backed up date information, since older DOS versions and DOS utilities probably don't save this properly. You can override this behaviour by using the /nt switch.
changed files
If during a restore, DOSLFNBK detects that the file size has changed, you'll be prompted as to whether you want to restore the LFN or not. If you choose to restore it, the date information will *not* be restored, as it is probably incorrect.
file attributes and the /na and /nf options
Many backup programs don't handle Win95 file attributes properly. They will skip hidden files or hidden directories, or change the attributes upon restore. Since some of the special features of directories in Win95 depend on the attributes, this can cause problems after a restore. To avoid this, DOSLFNBK does two things:
First, it checks that every directory and file recorded in the backup file exists during the restore. If any are missing, it prints a warning message. To skip this check, use the /nf (no full restore) option.
The second thing done to protect against attribute-challenged programs is to store information on files with any unusual attributes, whether they have long filenames or not. These include System, Hidden and Readonly files and directories, and also files using two directory attribute bits that are not normally used. During a restore, DOSLFNBK will restore any attribute bits except the SubDirectory and Volume attributes (because changing these would damage the disk structure) and the Archive attribute (because this is typically used to signal whether a file is backed up or not; one would expect it to change after a backup). If you don't want this special handling of attributes, use the /na option. Only long filename records will be backed up, and during a restore the file attributes of the file on the disk will be kept.
the /q quiet option, /v verbose option and the /d debug option
To show you the progress of a run, DOSLFNBK prints a dot for about every 10 directories examined or (in /v mode) prints the directory and file names. If it stops printing for more than a few seconds, something is probably wrong. Try running again with the /d debug log option, and if it stops again, please email me ( a copy of your log, along with a description of your system. I'm very interested inmaking DOSLFNBK as bug-free as possible.
During a restore, it normally prints a report of any changes made; with the /q option this report is suppressed.
the /all option to back up all filenames
Sometimes you may want a record of the names of every file on the disk. An easy way to get this is to run DOSLFNBK with the /all option. This will save the directory descriptions of every file and subdirectory on your disk. To view the listing, run again with the /l option. You can also make use of this during the restore to detect files that have changed since the backup, or files that were missed in a restore.
the /auto and /force options
The /force option tells DOSLFNBK to go ahead without stopping for several different warnings (e.g. overwriting the backup file). Use it in a batch file only when you're sure you always want it to go ahead.
The /auto option is the safe equivalent: it acts as though you accepted the default. In most cases, the default is to abort the run; however, when restoring a filename to a file that appears to have changed, the default is to skip the file.
the /orphans option for damaged directories
When damage occurs to a directory (perhaps by an old non-Win95 compatible program), often the long filename records are left "orphaned": they are no longer connected to any file. When this happens, the best thing to do is to use a disk repair program (e.g. SCANDISK) to repair the damage before running DOSLFNBK, because DOSLFNBK is written under the assumption that the disk structure is intact. DOSLFNBK makes an attempt to detect orphaned LFNs, and is 99% successful. When it detects any, it will stop and ask you whether to continue the operation (the default response is No). If you choose to continue a backup, then it will just skip over the orphans, and back up everything else. If you choose to continue a restore, it will delete the orphaned records. If there is other damage to your disk, it is possible that these actions are *not* desirable, and may result in an incomplete or unusable backup, or further damage to your disk on a restore.
If you have a lot of damage to your disk and are just trying to salvage what you can, you may not want to have to answer Yes to all those questions. In that case, you can use the /orphans option, which will make DOSLFNBK go ahead regardless of the consequences.
In case it is not clear: I would personally never use the /orphans option, and would almost never answer Yes if orphans were detected. If you do this and your disk ends up in a mess, you've only yourself to blame.
What you *should* do is avoid orphans in the first place: if you detect orphans somehow, stop using whatever program created them.
the /h option for high-level disk access
Normally DOSLFNBK uses low level methods to access the directory structure during a backup. This requires that the drive be using a FAT file system of some sort, and be locally connected. The /h option tells DOSLFNBK to use high level methods instead: this allows it to work on non-FAT disks, or over a network.
Unfortunately, this option only works on backups; there is no way to do a restore with such a disk. Another restriction is that the methods only work while Windows is running to provide high level long filename services.
the /s option to skip directories
The /s option tells DOSLFNBK to skip the back up or restore of a particular directory. This is meant as a workaround for the memory limitations in DOSLFNBK that are described below. You can use /s as often as necessary to skip multiple directories--the only limit is the command line length. Note that the directory name must be specified using the short aliases, e.g. "\PROGRA~1" instead of "\Program files". Relative directory paths using "." and ".." are not supported. If used in combination with the /from option, you should specify the *original* path name to skip, not the current one.
the LOCK and UNLOCK commands
Early versions of DOSLFNBK used the DOS LOCK and UNLOCK commands to lock the disk and prevent errors during restores. The current version does this internally. If you have an old batch file that runs LOCK, you'll get warning messages: "Unable to lock drive X:". Just remove LOCK from the batch file and the warnings will go away.
the irritating jump to full screen
There is one bug in Win95 that the internal locking shows up: if you try to restore LFNs to a disk that has any open files on it while in a DOS window, the window will suddenly switch to full screen. I don't know of any way to prevent this.
DOSLFNBK, disk defragmenters and directory sort utilities
You may be tempted to use an older DOS-based disk defragger or directory sort utility that doesn't understand long filenames, and then use DOSLFNBK to restore the long filenames. DON'T DO THIS! It is extremely likely to cause errors to your directory structure which can't be repaired except by hours and hours of work. The problem is that these programs usually leave a few files with wrong but apparently correct long filenames. You'll find that 90-95 percent of your disk is restored, but some number of files are not. It is extremely difficult and time consuming to find and repair these files. If you want to use these DOS-based programs, you should remove all long filenames first (e.g. using LFNBK, or by restoring from tape in DOS, or using LFNDEL). A better solution is to use Win95 compatible versions of these utilities. (Win95 comes with a defragger, and there are shareware directory sort utilities available, including mine.)
I have received several messages from people who have tried to use XCOPY and DOSLFNBK to back up their disk to a network drive or elsewhere, and then found on restore that Win95 won't boot properly. What appears to be the problem is that the 16 bit version of XCOPY does not handle file and directory attributes properly. DOSLFNBK will restore missing attributes, but if a file is not there, all it can do is warn you. As far as I know the only way to successfully use XCOPY in a backup scheme is to remove special attributes before the backup.
exit codes
When a run is successful, DOSLFNBK exits with ERRORLEVEL 0. When something goes wrong, it prints an error message and exits with a higher errorlevel. The currently defined error levels are:
99 - Syntax error
98 - Disk init error
97 - Disk read error
96 - Disk write error
95 - Disk directory error
94 - Directory init error
92 - Disk lock error
91 - Internal error
89 - Memory error
88 - Multitasker error
87 - Overwrite error
86 - Debug error
85 - Backup read error
84 - Backup write error
83 - Backup open error
82 - Backup close error
81 - Some directories were skipped because of low memory
80 - DOSLFNBK detected an error in the LFN structure on your disk. You should run SCANDISK or another disk repair program to do repairs.

Back to top

Memory Limitations:

When running, DOSLFNBK keeps copies of several directories in memory at once. It is written as a real mode DOS program and keeps all of this data in the low 640K of memory. This means that in a typical DOS session with 500K of memory available, DOSLFNBK will run out of memory when about 15,000 directory entries are in memory.

On a restore, up to 3 copies of each directory entry may be in memory at once, limiting DOSLFNBK to disks with fewer than 5000 directory entries in any branch of the directory tree. (The total number of files on the disk doesn't matter; what matters is the number of entries in a directory, its parent, grandparent etc., back to the root.)

When I wrote DOSLFNBK, I thought disks approaching this limit were very unusual. However, it *is* possible to have such a disk, and here's how to find out if you do: Run your backup with the /v verbose option. At the end, it will print a message something like
Used 255K; restore will require about 264K in DOS session.

If the amount of memory estimated for the restore is more than you have available (as reported by the DOS MEM command), you might have problems. You might not; the number reported is usually an overestimate.

If it ever turns out that you do run out of memory during a restore, you can still restore the LFNs by breaking up the restore operation into several steps, restoring different parts of your subdirectory tree separately. In the worst case (more than 5000 entries in a single subdirectory), you may have to temporarily move files out of the directory and restore the LFNs a few thousand (!!) at a time.

Since the original release, it has become clear that there are some common situations leading to very large directories. The Microsoft Plus! package includes one, and WWW browsers often create them while maintaining caches or history lists.

Unfortunately, the current version of DOSLFNBK doesn't handle these very well; it just skips these directories and prints a warning message and sets an error level on exit. I have added the /s option to allow you to skip particular directories during the backup or restore operation. A better solution that allows all directories to be backed up is in the works.

Back to top


DOSLFNBK works with your disk at a level below the file system, so if things go wrong during an LFN restore, it's conceivable that you could lose whole files or directories. I've tried to make it as safe as I can, but you should follow some simple precautions:

Back to top

Recovery from total disk failure:

If your boot disk fails, or you decide to repartition it, then you may need to do a full restore from a backup tape. Unfortunately, many Win95 backup programs provide *no way* to do this without re-installing Win95 from the original disks or CD ROM.

However, if you have a reliable DOS-based backup program, DOSLFNBK will let you do a complete restore from a backup. I've only had to do this twice, so these instructions aren't guaranteed to cover everything for every system, but they worked on mine.


Before your disk fails (i.e. right now! :-), you need to prepare the following:

  1. A Win95 startup disk. If you didn't create one when you installed Win95, start the Add/Remove Programs option in Control Panel, and click the Startup Disk tab. Then click the Create Disk button, and follow the instructions on-screen.
  2. A copy of your DOS-based backup/restore program on a floppy disk. It may require EMS memory; if so, you should put HIMEM.SYS and EMM386.EXE on your startup disk, and load them via CONFIG.SYS.
  3. If you use Drivespace disk compression, then you should also make sure that the MINI.CAB file from the installation disks or the CD ROM is in your Windows directory on the hard disk.
  4. A full backup of your disk(s). Just before creating this, run DOSLFNBK to save all of your long filenames. You'll need to create one backup file for each disk. It's fine to leave this on the hard disk so that it ends up on the backup; you don't need to have it on floppy disk.


Depending on the reason for your disk failure, you may be able to skip some of the early steps here. Read them over, and figure out where to start. If you have to, you can start again, so the only thing you lose by starting too far down is time.

  1. Make any necessary repairs to your hardware.
  2. Boot from your Startup disk, and use FDISK to partition your disk. Use "FORMAT c: /s" to reformat the disk and transfer the system files to it.
    NOTE: If you want to maintain the ability to boot to your old DOS version, I've been told that the Startup disk's FDISK will cause problems for you. You should boot the old DOS version and use its FDISK to partition your disk, and then reboot from the startup disk and use "SYS c:" to transfer the Win95 system files. After that, you can continue as before.
  3. (Optional) Transfer your tape backup software to your hard disk.
  4. If you're not planning to use Drivespace, you can skip down to step 8.
  5. If you want to compress your drive, you need to restore enough of Win95 to run Drivespace. Don't restore the whole disk; you might not have room for it. For most people, restoring the files in the root directory and the files in the \Windows directory should be enough. If you have any essential drivers in other directories, you'll need to restore them too. Finally, you should restore DOSLFNBK and the data file(s) containing the backed up long filenames.
    IMPORTANT: You should not overwrite IO.SYS, but you *should* overwrite MSDOS.SYS. It is a hidden read-only file in your root directory. A good way is to erase MSDOS.SYS before starting the restore (use ATTRIB from the Startup disk to remove the System, Hidden, Read-only attributes), and then tell your restore program not to overwrite existing files.
    Restore all those files now.
  6. Restore the long filenames by running
    DOSLFNBK c:\ /R /V /F backupfilename
  7. Remove the Startup disk, and reboot your system. You may get some errors about missing drivers (e.g. no sound card drivers), but things should basically work. Run DriveSpace to compress your drives the way you want.
  8. Reboot your system in DOS mode or from the Startup disk.
  9. Restore all rest of the files on all of your disks from the backup now. See the "IMPORTANT" note in step 5 about MSDOS.SYS and IO.SYS.
  10. Restore all the rest of your long filenames by running
    DOSLFNBK c:\ /R /V /F backupfilename
    and if you've also got a D: partition,
    DOSLFNBK d:\ /R /V /F backupfilename
    You may get messages about some long filenames already existing from your first restore; don't worry about those.
  11. Some restore programs set the archive bit on all restored files; you might want to turn it off (since you've still got those files backed up) at this point

Reboot your system, and things should be back as they were when you did your backup!

Back to top


DOSLFNBK is *not* public domain software. Releases up to version 1.6 were freeware, and you may use them at no charge. However, the current release is shareware. You may use it at no charge for an evaluation period of 30 days only.

You are free to distribute unmodified copies of the complete DOSLFNBK package, provided your total charge is no more than $1. The total cost of a compilation (e.g. a CD ROM) including DOSLFNBK must be no more than $1 per package in the compilation.

To continue to use DOSLFNBK beyond the 30 day evaluation period, you must register it. There are three possible registration levels available:

$10 simple registration (+$5 s/h, $15 total)
This registration fee gives you a license to use one copy of DOSLFNBK indefinitely. If you include an email address when you register I will notify you of new versions and how to obtain them yourself. I'll also attempt to answer emailed questions about DOSLFNBK from registered users.
$20 bonus registration (+$5 s/h, $25 total)
This registration fee also entitles you to use DOSLFNBK indefinitely. In addition to the license to use it, I will email you a collection of bonus programs that are not otherwise available. See my web page for the current list. I will also notify you of updates, and send one free update by email if you request it. Payment may be made in Canadian or US dollars (at par), or the GBP (Sterling) equivalent of $25 US. See below for how to avoid the handling charge.
$45 source code registration (+$5 s/h, $50 total)
DOSLFNBK was written in Borland Pascal 7.01, using the excellent Object Professional library from TurboPower Software. In addition to the benefits of the upgrade registration, the source code registration gives you the DOSLFNBK source code (including an object-oriented low-level disk access unit, access to the new Win95 DOS API functions, and a huge memory support unit, but not OPro). See below for how to avoid the handling charge.
License terms for the source code registration allow you to recompile DOSLFNBK for your own use but not to distribute the recompiled version to others.

Payment may be made in Canadian or US dollars (at par), or the UKP equivalent of the US dollar price. Any of the registrations can be done by sending a cheque or money order to:

Duncan Murdoch
354 Victoria St.
London, Ontario, Canada.
N6A 2C8

To order online via PayPal, click here.

You can also register or order source code from Digibuy.Com using MC, Visa, AmEx, or Discover card online at

Digibuy is for ordering only. I *cannot* be reached there. To contact me for information about dealer pricing, volume discounts, site licensing, the status of shipment of the product, the latest
version number or for technical information, write to me at the address above or the email address below. I'd especially like to hear bug reports and suggestions for improvements.

NOTE: If you send your registration directly to me or via PayPal, I will waive the $5 handling fee. The prices are then $10 for the simple registration, $20 for the bonus registration, and $45 for the source code registration.

Volume discounts are described online at

Site licenses and custom versions are also available; contact me by email to for details.

The latest version of DOSLFNBK is available from

Back to top

Release history:

0.0 - first beta test version
0.1 - kept file attributes of existing file during restore.
0.2 - made messages more informative; fixed bug in handling erased file entries; added check of overwrite of backup file; changed default name of backup file to BACKUP.LFN and made LFN the default backup extension; added /P option.
0.3 - fixed memory leak that caused run-time error 203 on large restore
0.4 - added check for successful write of backup file, added /force option.
0.5 - added report of memory use, /d option, many debugging messages
0.6 - cleaned up messages and debug log, removed disk size restriction, added progress dots for non-verbose runs.
1.0 - first public release --- same as 0.6
1.1 - unauthorized release
1.2 - documentation changes and addition of /s option
1.3 - improved memory management, stopped use of obsolete DOS service 1C, speeded up directory expansion on restore
1.4 - added /L option, support for relative path on command line, internal drive locking, support for SUBST etc. Changed exit codes to be compatible with LFNSORT.
1.5 - public release, same as 1.4c
1.6 - fixed bug in handling volume labels
1.7 - added integrity checks of disk structure, backup/restore/display of file attributes, checks for existence of backed up files, changed from freeware to shareware, /o option.
1.9 - fixed display of some special characters, added FAT32 support, added /from and /all options, added support for non-IOCTL drives
2.0 - fixed bug with FAT32 drives, bug with swapfile
2.1 - fixed bug with very large directories
2.2 - fixed confusing prompts, removed requirement for /L directory to exist, changed backup format, restored support for obsolete formats
2.3 - fixed bug with /force option and file size change, problems with directories full of erased file entries, added /auto
2.4 - added /q and /h options.
2.5 - fixed 64K cluster problem.
2.6 - fixed large directory problems.
2.7 - fixed occasional corrupted directory bug.

Back to top


The first version of DOSLFNBK was written based on the information in Robert Hummel's article on Win95 long filenames in the June/July 1995 issue of PC Techniques Magazine. Thanks are due to the beta testers, who suggested many improvements, and several of whom were put to considerable inconvenience by early versions that messed up their disks. M. Guffey made a lot of useful suggestions for improvements to the documentation. Several people sent me details of working with XCOPY.

Back to top

Last updated 12 October 2002
Send comments to
Do not use this email address for bulk email ("spam").