Copy short 8.3 filename in long mode (Windows)

1.6k Views Asked by At

Trying to copy from command line a file named "SCOOTE~1.txt" to a folder where there is a file called "Scooter - Cosmos.txt".

The problem is that copy will contract the name of "Scooter - Cosmos.txt" to "Scoote~1.txt" as well and will ask if I want to overwrite that file.

How can I literally copy the "SCOOTE~1.txt" without affecting other long-named files ? Suggestion of external command-line tools is accepted.

1

There are 1 best solutions below

1
On

Recreation of Problem

c:\Test> > "Scooter - Cosmos.txt" echo File with long name
c:\Test> md SFN
c:\Test> > "SFN\SCOOTE~1.TXT" echo File with short name
c:\Test> dir/s/x
 Volume in drive C is OS
 Volume Serial Number is BE3C-8BC1

 Directory of c:\Test

22/09/2017  08:51    <DIR>                       .
22/09/2017  08:51    <DIR>                       ..
22/09/2017  08:50                21 SCOOTE~1.TXT Scooter - Cosmos.txt
22/09/2017  08:51    <DIR>                       Test
               1 File(s)             21 bytes

 Directory of c:\Test\SFN

22/09/2017  08:51    <DIR>                       .
22/09/2017  08:51    <DIR>                       ..
22/09/2017  08:51                22              SCOOTE~1.TXT
               1 File(s)             22 bytes

     Total Files Listed:
               2 File(s)             43 bytes
               5 Dir(s)  104,170,942,464 bytes free

Here the current directory has a file with a long-name of Scooter - Cosmos.txt and a short-name of SCOOTE~1.TXT (Note: the short-name is already in place at this stage). Also, the directory SFN contains a file called SCOOTE~1.TXT – because this name "fits" in the 8.3 format, it does not have a separate short-name.

If we now try to copy this file into the current directory, because the short-/only name of the file being copied matches the short-name of the file already present, it prompts about overwriting:

c:\Test> copy "SFN\SCOOTE~1.TXT"
Overwrite c:\Test\SCOOTE~1.TXT? (Yes/No/All): n
        0 file(s) copied.

Single-Instance Fix

As eryksun suggested, you can use the fsutil file setshortname command to fix one-off clashes by changing the short-name of the file in the current directory:

c:\Test> fsutil file setshortname "Scooter - Cosmos.txt" SCOOTE~2.TXT

c:\Test> dir/x
 Volume in drive C is OS
 Volume Serial Number is BE3C-8BC1

 Directory of c:\Test

22/09/2017  09:09    <DIR>                       .
22/09/2017  09:09    <DIR>                       ..
22/09/2017  08:50                21 SCOOTE~2.TXT Scooter - Cosmos.txt
22/09/2017  08:51    <DIR>                       SFN
               1 File(s)             21 bytes
               3 Dir(s)  104,168,501,248 bytes free

c:\Test> copy "SFN\SCOOTE~1.TXT"
        1 file(s) copied.

c:\Test> dir/x
 Volume in drive C is OS
 Volume Serial Number is BE3C-8BC1

 Directory of c:\Test

22/09/2017  09:09    <DIR>                       .
22/09/2017  09:09    <DIR>                       ..
22/09/2017  08:50                21 SCOOTE~2.TXT Scooter - Cosmos.txt
22/09/2017  08:51                22              SCOOTE~1.TXT
22/09/2017  08:51    <DIR>                       SFN
               2 File(s)             43 bytes
               3 Dir(s)  104,168,464,384 bytes free

Here we can see that the short-name of Scooter - Cosmos.txt has been changed so that it no longer clashes with SCOOTE~1.TXT; the copy proceeds with no warning and both files sit side-by-side in the current directory.

Multiple-Instance Fix

If there are (or could be) several clashes with the files in the target directory, an alternative approach is to use the fsutil 8dot3name strip command to remove the 8.3-format short-names from all files at once:

c:\Test> fsutil 8dot3name strip .
Scanning registry...

Total affected registry keys:                   0

Stripping 8dot3 names...

Total files and directories scanned:            2
Total 8dot3 names found:                        1
Total 8dot3 names stripped:                     1

For details on the operations performed please see the log:
  "C:\Users\xxxxxxxx\AppData\Local\Temp\8dot3_removal_log @(GMT 2017-09-22 08-36-00).log"

c:\Test> dir/x
 Volume in drive C is OS
 Volume Serial Number is BE3C-8BC1

 Directory of c:\Test

22/09/2017  09:36    <DIR>                       .
22/09/2017  09:36    <DIR>                       ..
22/09/2017  08:50                21              Scooter - Cosmos.txt
22/09/2017  09:33    <DIR>                       SFN
               1 File(s)             21 bytes
               3 Dir(s)  104,154,349,568 bytes free

As can be seen, the file Scooter - Cosmos.txt no longer has a short-name, so there is no clash when SCOOTE~1.TXT is copied into the current directory:

c:\Test> copy "SFN\SCOOTE~1.TXT"
        1 file(s) copied.

c:\Test> dir/x
 Volume in drive C is OS
 Volume Serial Number is BE3C-8BC1

 Directory of c:\Test

22/09/2017  09:40    <DIR>                       .
22/09/2017  09:40    <DIR>                       ..
22/09/2017  08:50                21              Scooter - Cosmos.txt
22/09/2017  08:51                22              SCOOTE~1.TXT
22/09/2017  09:33    <DIR>                       SFN
               2 File(s)             43 bytes
               3 Dir(s)  104,151,703,552 bytes free

NOTE: The first stage of this command – Scanning registry... – may take some time as it is looking through the registry for references to the 8.3-format names that are about to be removed. See fsutil 8dot3name strip /? for more details of this command.

Caution (Applies to both methods)

As the help from the fsutil 8dot3name strip /? command says:

This command permanently removes 8dot3 file names from your volume. It will list the registry keys pointing to the stripped 8dot3names but will not modify the affected registry keys. Stripping will not be performed on files with full path names longer than the maximum path length of 260 characters.

both these commands modify (or remove) the 8.3-format names of selected files. If you have any references to the files concerned (either in the registry, configuration files, or elsewhere in .BAT files etc.) then these references will no longer be valid. Use either solution with due caution.