Cadzow Knowledgebase


Welcome
Contact Us
Professional
Services

Consulting
Knowledgebase/
Site Search

Remote Support

Print Friendly

Unpredictable Results with Windows' MOVE Command

The Windows Command Processor (CMD.EXE) provides a MOVE command to move files from one location to another. For example:

move C:\Folder1\File*.txt D:\Folder2

However, it is subject to a glitch which results in unpredictable results when many files have similar names. Consider the following list of archive files, named with date-stamps:

20200102A.zip
20200103A.zip
20200104A.zip
20200106A.zip
20200107A.zip
20200108A.zip
20200109A.zip
20200110A.zip
20200113A.zip
20200114A.zip
20200115A.zip
20200116A.zip
20200117A.zip
20200120A.zip
20200121A.zip
20200122A.zip
20200123A.zip
20200124A.zip
20200125A.zip
20200128A.zip

Suppose we have a script which relocates these files based on the “year” component of the name:

for /L %%x in (1990,1,2050) do move %%x*.zip Archive-%%x

This command steps through all possible years (say, 1990 to 2050) and moves the files from each year into a subfolder. So all of the files beginning with “2020” will move into the “Archive-2020” folder.

However, this does not always work as expected. This is because by default Windows generates an “MS-DOS style” 8.3 name for each file. The DIR command with /X will show the generated short names:

02/01/2020  05:53 PM       497,862,906 202001~1.ZIP 20200102A.zip
03/01/2020  06:08 PM       497,945,358 202001~2.ZIP 20200103A.zip
04/01/2020  01:07 PM       497,965,310 202001~3.ZIP 20200104A.zip
06/01/2020  06:00 PM       500,386,393 201E9A~1.ZIP 20200106A.zip
07/01/2020  06:28 PM       498,252,743 202001~4.ZIP 20200107A.zip
08/01/2020  05:50 PM       500,696,568 203702~1.ZIP 20200108A.zip
09/01/2020  05:32 PM       500,857,721 204442~1.ZIP 20200109A.zip
10/01/2020  05:42 PM       501,098,264 2014ED~1.ZIP 20200110A.zip
13/01/2020  05:45 PM       501,229,702 20C8FB~1.ZIP 20200113A.zip
14/01/2020  05:41 PM       498,974,044 20D11F~1.ZIP 20200114A.zip
15/01/2020  07:11 PM       501,575,653 205200~1.ZIP 20200115A.zip
16/01/2020  05:21 PM       501,709,862 20B8A7~1.ZIP 20200116A.zip
17/01/2020  05:21 PM       501,815,416 207B67~1.ZIP 20200117A.zip
20/01/2020  05:43 PM       501,993,239 205496~1.ZIP 20200120A.zip
21/01/2020  05:33 PM       502,173,855 20B611~1.ZIP 20200121A.zip
22/01/2020  06:28 PM       499,893,333 200D51~1.ZIP 20200122A.zip
23/01/2020  05:44 PM       499,978,669 200E46~1.ZIP 20200123A.zip
24/01/2020  06:13 PM       500,040,974 2026C8~1.ZIP 20200124A.zip
25/01/2020  05:48 PM       500,066,743 207442~1.ZIP 20200125A.zip
28/01/2020  06:18 PM       500,211,354 20D834~1.ZIP 20200128A.zip

In this example, the file 20200110A.zip is actually moved into the “2014” folder because the short name is 2014ED~1.ZIP.

The remedy is to use PowerShell, which doesn't have the same glitch:

for /L %%x in (1990,1,2050) do powershell move-item %%x*.zip Archive-%%x

Copyright © 1996-2020 Cadzow TECH Pty. Ltd. All rights reserved.
Information and prices contained in this website may change without notice. Terms of use.


Question/comment about this page? Please email webguru@cadzow.com.au