LoginSignup
0
0

【bat】リストを使用したファイルの移動

Last updated at Posted at 2024-02-02
moveFile.bat
@echo off
set "sourceFolder=C:\元のフォルダのパス"
set "destinationList=C:\移動先のファイル・パスのリスト.txt"

if exist "%destinationList%" (
    for %%a in ("%sourceFolder%\*.*") do (
        set "fileName=%%~nxa"
        set "destinationPath="
        
        rem 指定したファイル名に一致する行を検索し、パスを取得
        for /f "usebackq tokens=1,* delims=," %%b in ("%destinationList%") do (
            if /i "%%b"=="%fileName%" (
                set "destinationPath=%%c"
                goto MoveFile
            )
        )
        
        echo ファイル "!fileName!" の移動先が見つかりませんでした。
        goto ContinueLoop
        
        :MoveFile
        if not exist "%destinationPath%" mkdir "%destinationPath%"
        
        move /Y "%sourceFolder%\!fileName!" "%destinationPath%\"
        echo ファイル "!fileName!""!destinationPath!" に移動されました.
        
        :ContinueLoop
    )
) else (
    echo 移動先のファイル・パスのリストが見つかりませんでした。
)

pause

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0