2

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.

asked Sep 22, 2017 at 6:42
4
  • You can change the short name with fsutil file setshortname "Scooter - Cosmos.txt" SCOOTE~2.TXT. Otherwise you'll have to copy "SCOOTE~1.txt" to a different name. Commented Sep 22, 2017 at 7:36
  • Original file names must be kept. They do not conflict anyway. Commented Sep 22, 2017 at 7:44
  • The short name is just another name for the file in the directory. It's a lot like a hard link. So the existing names do conflict. Commented Sep 22, 2017 at 7:46
  • @Eryksun's solution will alter the short name of the Scooter - Cosmos.txt file so it no longer clashes with the short/only name of the SCOOTE~1.txt file. The normally-visible names of both will remain the same. Commented Sep 22, 2017 at 7:49

1 Answer 1

2

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\Temp8円dot3_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.

answered Sep 22, 2017 at 9:17
Sign up to request clarification or add additional context in comments.

1 Comment

Beware of the LFN 260+ issue around fsutil 8dotname strip ... command, as long as it can not access the LFN 260+ paths the same way as others at least on Windows 8. So either you use LFN+SFN or the LFN only. Attempt to strip LFNs files and folders from already created SFNs is a half working solution.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.