Converting UNIX Filenames to MS-DOS
Ed Schaefer and Fred Brunet
As the boundary between UNIX and MS-DOS software development
to blur, a system administrator may routinely need to
move files between
the two. The MS-DOS filename is a base name of up to
with an extension of three characters or fewer. UNIX
conventions are far more liberal than MS-DOS, so we
have developed a
UNIX utility, dosnames, which renames every filename
suppplied on the
command line to an MS-DOS compatible filename. As each
eligible file is
renamed, the new MS-DOS name and the original UNIX filename
in a file called dosnames.lst. Running the utility a
second time renames
the MS-DOS files back to their UNIX original filenames.
The Conversion Rules
If the dosnames.lst file does not exist, every file
listed in standard
input which violates the basic MS-DOS convention is
renamed using the
following conversion rules:
1. Any base filename of more than eight characters is
reduced to eight
2. Any filename extension longer than three characters
is reduced to
3. All filenames are downshifted, meaning any filename
with mixed case
is also downshifted.
4. Directories listed among the arguments and any files
directories are skipped.
5. Any filename with an unprintable character is skipped.
6. Any filename with more than one period is modified
to contain only
one period. In UNIX, a hidden file is defined as a file
beginning with a
period, but the hidden file attribute is more than a
in DOS, so all UNIX hidden files are ignored.
7. Any filename that converts to a name that already
exists has a
two-digit number inserted before the extension, allowing
process up to 99 UNIX files with the same first six
If the file dosnames.lst exists, the files listed are
restored to their
original name using the UNIX mv command. At the end
of the conversion,
the dosnames.lst file is deleted.
dosnames processes filenames supplied as command-line
than reading every file in the directory. To execute
dosnames for only
individual files on the command line:
dosnames long_file1 long_file2
To execute dosnames for every file in the present working
Given the following directory listing in the present
12345678.123 dosnames.c long_name1.c long_name2.c two.dots.
BIGNAME ok_dir Uppercase cat.file
you can run:
which provides the following listing to standard output:
9 files to process:
Renaming BIGNAME to bigname
Renaming cat.file to cat.fil
Renaming dosnames.c ok
Renaming ok_dir skipping directory
Renaming long_name1.c to long_nam.c
Renaming long_name2.c to long_n00.c
Renaming two.dots. to two.dots
Renaming Uppercase to uppercas
and writes a record of how the names were mapped to
following listing shows the contents of dosnames.lst.
The first column
is the MS-DOS filename, and the second column is the
original UNIX name.
Because the first eight characters of long_name1.c and
the same, the seventh and eighth characters of the DOS
changed to a sequence number. Up to 99 files (e.g.,
One enhancement to this program would be to change the
For example, the UNIX hidden file method could be changed.
that reads filenames from standard input instead of
from the command
line would avoid operating system limitations, allowing
usage such as:
find . -print|dosnames
About the Authors
Ed Schaefer is a frequent contributer to Sys Admin.
He is an Informix
Database Administrator and UNIX administrator for jeTECH
Data Systems of
Moorpark, CA, where he develops Time and Attendance
Software. He can be
reached at email@example.com.
Fred Brunet has a B.S. in computer science from California
University., Northridge and is currently a C and Informix
working on UNIX and MS-DOS platforms for jeTECH Data