batch file Copy files with certain extensions from multiple directories into one directory

后端 未结 5 1397
别那么骄傲
别那么骄傲 2020-11-30 19:33

I\'m a newbie, so bear with me...

I am trying to copy all .doc files that I have scattered throughout several subdirectories of one main directory into

5条回答
  •  既然无缘
    2020-11-30 20:17

    Brandon, short and sweet. Also flexible.

    set dSource=C:\Main directory\sub directory
    set dTarget=D:\Documents
    set fType=*.doc
    for /f "delims=" %%f in ('dir /a-d /b /s "%dSource%\%fType%"') do (
        copy /V "%%f" "%dTarget%\" 2>nul
    )
    

    Hope this helps.

    I would add some checks after the copy (using '||') but i'm not sure how "copy /v" reacts when it encounters an error.

    you may want to try this:

    copy /V "%%f" "%dTarget%\" 2>nul|| echo En error occured copying "%%F".&& exit /b 1
    

    As the copy line. let me know if you get something out of it (in no position to test a copy failure atm..)

提交回复
热议问题