Abbreviated filenames and DOS command lines

My DOS kung fu is getting quite rusty, unfortunately.

Is there a way to force the command line utility in Windows NT and later versions to NOT truncate directory and file names with the ~1 substitution?

As an example, the directory reference C:\LONGDIRNAME becomes C:\LONGDI~1.
This is problematic, because I’m working with 3 long names that are not unique within the first 6 characters, and I can’t change the names because of hardcoded references within various programs each contain.

My ultimate goal is a command script to perform a single function with no ability to change anything related to it’s execution, and this directory name problem causes the procedure to fail because of ‘Invalid Directory’…

Can you provide a bit of context? Are you wanting to enter long names in commands, or are you wanting output (such as the result of a DIR command) to be returned in long name format, or both?

The former (making it accept long names in commands) may be achieved by enclosing the entire path in quotes, so to delete a file it would be DEL “C:\Long Dir Name\Long File Name.ext” /[Switches]

I’m after both. I also tried the double quotes for C:> cd “C:\longdirname”, and got errors regarding invalid format.

It’s still not clear what you want to do, but in 2000 and XP “dir /x” will show you the long and short file names if that helps.

If the utility is a 16-bit DOS executable then there is no way to make them use long file names.

When writing command scripts I have found that things get all goofed up if you pass in a short dirname one time and a long one the next, regardless of if there are quotes.

The simplest fix for that I have is to use the “~” character when referencing arguments. This strips quotes from the argument.

Example: bozo.cmd


@echo Argument 1: %~1
@echo Argument 2: %~2
@echo Argument 3: %~3

Now if you do this:

C> bozo “C:\Program Files\Microsoft” C:\Program Files\Microsoft

you get this:

Argument 1: C:\Program Files\Microsoft
Argument 2: C:\Program
Argument 3: Files\Microsoft

This allows you to conveniently add quotes in more controlled fashion, regardless of whether or not the script caller had them.