我是一个完整的新手脚本。我想知道是否有人会帮我创建一个脚本。我正在查找的脚本是执行查找和移动过程的批处理文件。该查找将在dicom文件中搜索文本字符串(示例患者ID)。此外,查找也需要在子文件夹中搜索。此外,查找将查找的文件扩展名为.dcm或.raw。一旦查找完成并找到包含文本字符串的文件。我想要脚本,然后将它找到的文件复制到桌面上。任何帮助,将不胜感激。脚本执行搜索和文件复制
回答
这应该为你做。要查看命令行中每个命令类型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
bug)
@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
方法2可能会给出不正确的结果,因为有关8.3短文件名的讨厌的FINDSTR错误。有关更多信息,请参见[Windows FINDSTR命令的未记录功能和限制?](http://stackoverflow.com/q/8844868/1012053)。 – dbenham
@dbenham谢谢,我还没有看到这篇文章。我会将其添加到我的答案中。 –
setlocal enabledelayedexpansion
for /r C:\folder %%a in (*.dcm *.raw) do (
find "yourstring" "%%a"
if !errorlevel!==0 copy "%%a" "%homepath%\Desktop" /y
)
+1 - 您可能想要抑制FIND的输出。也不需要延迟扩展。 (* .dcm * .raw)do> nul找到“yourstring”“%% a”&& copy“%% a”“%homepath% \桌面“/ y' – dbenham
谢谢,是的,一个班轮是伟大的,它节省了延迟扩张的需要。 –
- 1. Shell脚本搜索和复制
- 2. 如何执行文本文件的二进制搜索
- 3. shell脚本文件搜索
- 4. Python文件搜索脚本
- 5. 文件搜索bash脚本
- 6. 执行TCL脚本的搜索路径
- 7. 简单的shell脚本来复制文件和文件夹,并执行命令
- 8. PHP脚本搜索CSV文本文件
- 9. SSIS脚本任务搜索文本(如果可用的复制文件)
- 10. 使用.bat脚本自动执行文件复制
- 11. Powershell:文件完成复制后执行脚本
- 12. ssh脚本和复制文件
- 13. shell脚本复制文件
- 14. Powershell复制文件脚本
- 15. Bash脚本复制文件
- 16. 在目录中搜索特定字符串的XML文件,然后使用bat脚本执行复制操作
- 17. 执行二进制搜索
- 18. 文本框复制到搜索框
- 19. 用于远程复制和脚本执行的Ansible剧本
- 20. shell脚本搜索和替换文本文件
- 21. 脚本来搜索文件和重命名文件
- 22. 在文件插入文件后恢复执行shell脚本
- 23. 执行搜索喜欢谷歌搜索文本框
- 24. Shell脚本,字符串搜索文件
- 25. Shell脚本搜索常规文件
- 26. Python脚本来搜索文件
- 27. R - 重复执行脚本
- 28. 用文本IO双击可执行文件制作ruby脚本?
- 29. Excel搜索和复制
- 30. jquery重复文本搜索和切割
漂亮类似于http:// stackoverflow.com/questions/8750206/vbscript-to-find-and-move-文件 - 自动呢? – RhysW