简体   繁体   中英

How to ignore 8.3 filename for “move” command in batchscript?

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

  • F010199004524001_904.XML
  • F010199805946001_737.XML
  • F010199904725001_611.XML
  • F030390114543001_901.XML
  • F030390114544001_257.XML
  • F030390114545001_901.XML

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?

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\"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM