2017-11-23 4 views
0

私は1つの場所(すべて同じフォルダ内)にPDFファイルを持っています。ファイル名から3つの有益な情報を取得する必要があります。バッチウィンドウ - 異なるフォルダにある多くのファイルの名前を変更するループを作成するにはどうすればよいですか?

そして、私はPDFから取り込んだこれらの情報で名前を変更する必要がある別の場所(フォルダごとに1枚の画像)に.jpgファイルを持っています。

私のスクリプトは、情報を見つけ出し、保存して名前を変更できますが、ディレクトリ内の最初のファイルに対してのみ機能し、停止します。 情報を取得するPDFファイルがなくなるか、名前を変更するための.jpgファイルがなくなるまで、ループを実行する必要があります。

誰かがこのスクリプトをループで実行できるように手伝ってもらえますか?

echo off 
setLocal EnableDelayedExpansion 

rem User input 
SET /P datework= Please type the date you want to work (format yyyymmdd): 

rem Folder where the PDFs are located - extract the useful information from file name 
cd /D C:\Users\A\Desktop\A_tests\QC\PDF\%datework%\ 

for %%i in (*.pdf) do (
    set RcvLn=%%i 
    set RcvLn=!RcvLn:~0,4! 
    set GunStn=%%i 
    set GunStn=!GunStn:~5,4! 
    set Node=%%i 
    set Node=!Node:~10,4! 
) 

rem Rename the pictures using the values stored on the variables 
xcopy /Y "C:\Users\A\Desktop\A_tests\QC\UHD73\Node Deployment\%datework%\Node %Node%\*.jpg" "C:\Users\A\Desktop\A_tests\QC\UHD73\Node Deployment\%datework%\Node%Node%_RL%RcvLn%_GS%GunStn%.jpg" 

答えて

0

あなたは、ファイルごとにループの内部で各変数を設定したが、その後、あなたは一度だけ、XCOPYを行いますループの外にXCOPYを行います。だから私たちはむしろループ内でxcopyを実行します。

echo off 
setLocal EnableDelayedExpansion 

rem User input 
SET /P datework= Please type the date you want to work (format yyyymmdd): 

rem Folder where the PDFs are located - extract the useful information from file name 
cd /D C:\Users\A\Desktop\A_tests\QC\PDF\%datework% 

for %%i in (*.pdf) do (
    set RcvLn=%%i 
    set RcvLn=!RcvLn:~0,4! 
    set GunStn=%%i 
    set GunStn=!GunStn:~5,4! 
    set Node=%%i 
    set Node=!Node:~10,4! 
    echo xcopy /Y "C:\Users\A\Desktop\A_tests\QC\UHD73\Node Deployment\!datework!\Node !Node!\*.jpg" "C:\Users\A\Desktop\A_tests\QC\UHD73\Node Deployment\!datework!\Node!Node!_RL!RcvLn!_GS!GunStn!.jpg" 
) 
+0

ありがとうGerhard!そのような簡単な解決策..私はそれが私にそれを見るためには昨夜遅すぎたと思います。 :P :) –

関連する問題