我是一个脚本新手。我想知道是否有人会帮助我创建脚本。我正在寻找的脚本是执行查找和移动过程的批处理文件。该查找将在 dicom 文件上搜索文本字符串(例如患者 ID)。此外,查找还需要在子文件夹中进行搜索。此外,要查找的文件扩展名是 .dcm 或 .raw。一旦查找完成并找到包含文本字符串的文件。我想要脚本然后将它找到的文件复制到桌面。对此的任何帮助将不胜感激。
问问题
762 次
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 /?
...
方法一:(推荐)
:: 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 回答