3

I have a simple batch file copying a large list of images from a network drive to a local drive which I had to stop in the middle of running.

c:\pic>copy i:\pictures\*.*

It appears to be copying in alphabetical order.

Any idea if that would be the default?

I'd like to restart from the middle as it takes a very long time to copy.

Mofi
  • 46,139
  • 17
  • 80
  • 143
shoshana
  • 31
  • 1
  • 4
  • Looks like a similar question to this one https://stackoverflow.com/questions/4228807/copy-files-without-overwrite – spikey_richie May 26 '17 at 15:06
  • I wasn't thinking of checking if it exists or the date of the file - I wanted a quick answer on the sequence of the copy function. I can check the date of the file - most files will exist already from a previous copy but many of the images have been updated. – shoshana May 26 '17 at 15:10

1 Answers1

8

All commands using a wildcard pattern to process a list of files or directories call the same Windows kernel functions which call the driver of the file system to return the file/directory names matching the pattern.

The commands COPY, DEL, DIR, FOR, etc. do not sort file names matching a wildcard pattern before processing. DIR has option /O to request an ordered output depending on next character.

NTFS (New Technology File System) returns file names matching a wildcard pattern always in alphabetic order because of adding file/directory names in alphabetic order to the master file table as eryksun explained in his comments.

But other file systems like the FAT based file systems FAT16, FAT32 or exFAT also common on Windows don't do that. The drivers of those file systems return the file/directory names as currently stored in file allocation table which means the order of file names is not sorted at all.

It looks like the source drive uses NTFS. For that reason the files were copied in alphabetic order.

But please note that there are different methods for alphabetic ordering of strings. For example an alphabetic order can be strictly according to code values of the characters or can take region and language specific aspects into account. A language specific alphabetic sort is often called a locale alphabetic sort where for example for German ä=a, Ä=A, etc. although the code values of the characters are different.

Applications often use also an alphanumeric sort algorithm which means the sort order for the 3 files with the names Test1.txt, Test10.txt and Test2.txt (alphabetic code value based sort) is not as listed here, but Test1.txt, Test2.txt and Test10.txt.

So as eryksun wrote in his third comment, the ordering of the file names of NTFS can be different to the order of file names used by Windows Explorer (see Sort order in Windows Explorer) or to command DIR with option /ON.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • 4
    NTFS stores directory entries in sorted tree based on an uppercase Unicode ordinal sort (using the case mapping table the was active when the volume was formatted), so it's also returning the entries in stored order. ;-) – Eryk Sun May 26 '17 at 17:53
  • `copy` also filters out system and hidden files -- and resets the read-only attribute. – Eryk Sun May 26 '17 at 17:54
  • @eryksun Thanks for this deep insight information about NTFS entry storage which I have not known (and for which I have never searched for). Good to know. – Mofi May 26 '17 at 18:01
  • 1
    Most file systems will list a directory in the stored order. Sorting the result in the file-system driver in the kernel is not ideal. It's best to leave the sorting to user mode. Even with NTFS the ordinal sort it uses isn't what Explorer uses or what cmd's `dir /on` uses. – Eryk Sun May 26 '17 at 18:13
  • "NTFS (New Technology File System) returns file names matching a wildcard pattern **always in alphabetic order**" is not correct. [Each locale has its own order which may be very different from English one](https://en.wikipedia.org/wiki/Alphabetical_order#Language-specific_conventions). http://www.unicode.org/reports/tr10/#Introduction, https://msdn.microsoft.com/en-us/globalization/mt662313.aspx – phuclv May 27 '17 at 11:53
  • 2
    [The NTFS file system internally maintains directory entries in a B-tree structure, which means that the most convenient way of enumerating the directory contents is in B-tree order, which if you cover one eye and promise not to focus too closely looks approximately alphabetical for US-English. (It's not very alphabetical for most other languages, and it falls apart once you add characters with diacritics or anything outside of the Latin alphabet, and that includes spaces and digits!)](https://blogs.msdn.microsoft.com/oldnewthing/20140304-00/?p=1603) – phuclv May 27 '17 at 11:53