windowsbatch-filecmdmoveshort-filenames

How to ignore 8.3 filename for "move" command in batchscript?


I have to move a lot of xml-Files, named as follow:

in my batch-file, there's this line:

move C:\source\F01*.xml C:\target\F01\

Now I have the problem, that some of the files have a different 8.3-filename, for example

"F030390114545001_901.XML" has the name "F01FCF~1.XML" so this file is also moved in the directory "F01".

The command "fsutil 8dot3name strip" in my case is useless, because the batch is running on a 2003 server.

Is there any type of workaround or alternative commands to solve this problem?


Solution

  • for /f %%a in ('dir /b /a:-d "c:\source"^| findstr /i /b "F01"^|findstr /i /e ".xml"') do (
       move "%%~fa" "C:\target\F01\"
    )
    

    this?

    EDIT

    findstr filtering can be done with a single expression -

    findstr /beri "f01.*xml"
    

    so

    for /f %%a in ('dir /b /a:-d "c:\source"^| findstr /beri "f01.*xml"') do (
       move "%%~fa" "C:\target\F01\"
    )