私はスクリプトの完全な初心者です。誰かが私にスクリプトを作成するのを手伝ってくれるかどうか疑問に思いました。私が探しているスクリプトは、検索と移動のプロセスを実行するためのバッチファイルです。検索では、dicomファイルでテキスト文字列(患者IDの例)を検索します。また、検索ではサブフォルダーも検索する必要があります。さらに、検索で検索されるファイル拡張子は.dcmまたは.rawです。検索が完了し、テキスト文字列を含むファイルが見つかったら。スクリプトを使用して、見つかったファイルをデスクトップにコピーします。これに関する助けをいただければ幸いです。
2 に答える
3
setlocal enabledelayedexpansion
for /r C:\folder %%a in (*.dcm *.raw) do (
find "yourstring" "%%a"
if !errorlevel!==0 copy "%%a" "%homepath%\Desktop" /y
)
于 2012-12-13T18:07:54.177 に答える
1
これでうまくいくはずです。コマンド ラインの各コマンド タイプで使用できるすべてのオプションを表示するには、次の手順を実行しますcommand /?
。
echo /?
for /?
find /?
xcopy /?
findstr /?
...
方法 1: (推奨)
:: No delayed expansion needed.
:: Hide command output.
@echo off
:: Set the active directory; where to start the search.
cd "C:\Root"
:: Loop recusively listing only dcm and raw files.
for /r %%A in (*.dcm *.raw) do call :FindMoveTo "patient id" "%%~dpnA" "%UserProfile%\Desktop"
:: Pause the script to review the results.
pause
goto End
:FindMoveTo <Term> <File> <Target>
:: Look for the search term inside the current file. /i means case insensitive.
find /c /i "%~1" "%~2" > nul
:: Copy the file since it contains the search term to the Target directory.
if %ErrorLevel% EQU 0 xcopy "%~2" "%~3\" /c /i /y
goto :eof
:End
方法 2: ( FINDSTR/s
バグのため推奨されません)
@echo off
for /f "usebackq delims=" %%A in (`findstr /s /i /m /c:"patient id" *.dcm`) do xcopy "%%~dpnA" "%UserProfile%\Desktop\" /c /i /y
for /f "usebackq delims=" %%A in (`findstr /s /i /m /c:"patient id" *.raw`) do xcopy "%%~dpnA" "%UserProfile%\Desktop\" /c /i /y
pause
于 2012-12-13T17:40:33.773 に答える