windows使用bat操作批量复制/移动目标文件

1.创建文本文件,使用写字板/nodepad++打开编辑,输入以下代码
    @echo off
        setlocal

    set "sourceFolder=(源文件夹)"
    set "destinationFolder=(目标文件夹)"

    set "fileList=(关键字 多个关键字使用空格隔开)"

        if not exist "%destinationFolder%" mkdir "%destinationFolder%"

        for %%F in (%fileList%) do (
        (复制copy 移动move) "%sourceFolder%\*%%F*" "%destinationFolder%\"
        )

    echo Files copied successfully!

    endlocal

举例:

F:\x\demo\1\allfile(源文件夹)中带有"YX100042200 YX200000056 YX200001565 YX200565463"的文件 复制至 F:\x\demo\2\newfile(目标文件夹)

示例代码:

    @echo off
        setlocal

    set "sourceFolder=F:\x\demo\1\allfile"
    set "destinationFolder=F:\x\demo\2\newfile"

    set "fileList=YX100042200 YX200000056 YX200001565 YX200565463"

        if not exist "%destinationFolder%" mkdir "%destinationFolder%"

        for %%F in (%fileList%) do (
    copy "%sourceFolder%\*%%F*" "%destinationFolder%\"
        )

    echo Files copied successfully!

    endlocal

2.把文件名称改为.bat后缀,例如:copy.bat

3.双击运行

你可能感兴趣的:(windows,服务器)