In which order does command COPY copy files from source to destination?

后端 未结 1 485
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 12:26

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:         


        
1条回答
  •  时光说笑
    2021-01-22 12:43

    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.

    0 讨论(0)
提交回复
热议问题