リストアップされたファイルを別のディレクトリに移すバッチファイル

 ファイルをリストアップしたファイル list.txt があって、そこに記述されたファイルのみを別のディレクトリに移す。
gist → https://gist.github.com/3051671


 バッチファイル。第一引数にリストファイルを、第二引数に移動先ディレクトリを指定する。

@echo off

if "%1" == "" (
    echo The first argument specifies the file, please
    goto :error
)
if "%2" == "" (
    echo The second argument specifies the directory, please
    goto :error
)

for /F "delims=" %%a in (%1) do (
    if exist %%a (
        mv %%a %2
        echo %%a moves to %2\%%a
    )else (echo %%a is not exist)
)
goto :end

:error
echo input error
:end


 使い方

> mv_from_filelists.bat list.txt target_directory


 リストのファイルの例:list.txt

a.txt
b.txt
c.txt

 ちなみにスーパーpre記法で bat のハイライトは dosbatch を指定するとできる。