Windows batch copy files from subfolders to one folder

前端 未结 4 537
庸人自扰
庸人自扰 2021-02-04 06:45

I had tried to make batch script that copies all *.tif files located in D:\\images(random named subfolders here) to d:\\all.

xcopy D:\\Downloads\\*.TIF D:\\temp\         


        
4条回答
  •  悲&欢浪女
    2021-02-04 07:04

    FOR is your friend. Read HELP FOR on the /R option and the %~nx variable substitution; and then try this very simple code.

       pushd d:\downloads
       for /r %%a in (*.tif) do (
         echo COPY "%%a" "d:\temp\%%~nxa"
       )
       popd
    

    watch carefully the results and then remove the ECHO command.

    You will have to refine the code to cope with errors, duplicate names, edge cases, names with reserved characters, race conditions, cosmic events...

提交回复
热议问题