
[已解決]批處理怎樣查找文本的路徑【更新】最后由 xudaweb 于 -8-28 09:34問題描述:1. 路徑不同的文件夾內(nèi)含有相同的文本test.txt, 如:C:test 2test.txt, c:1_temptest.txt,c:23test.txt 等很多個(gè)同名的文本...2. 在所有的test.txt中查找指定的字符串string:ABC1233. 如果查找到字符串,則反饋查找到字符的文本的完整路徑(最好能直接打開其路徑)。本人新人,折騰了好久,沒有任何進(jìn)展,遇到的問題:a, 用for無法指定不同路徑下test.txtb, 用find查找后,文本的路徑截取不出來c, 無法直接打開其路徑試了好多終于試出來了,現(xiàn)做如下更新,希望能給跟我同樣困惑的人一點(diǎn)點(diǎn)幫助。i. 直接打開搜索到文本
ii. 搜索到文本后直接打開文本當(dāng)前路徑nclick="copycode($('code0'));">復(fù)制代碼
- @echo off
- set /p str=Please input the string:
- for /f delims= %%i in ('dir /s /b test.txt') do (
- findstr /i /c:%str% %%i && (echo %%i & start %%i)
- )
iii. 搜索到文本后直接打開文本的上一級(jí)路徑nclick="copycode($('code1'));">復(fù)制代碼
- @echo off
- set /p str=Please input the string:
- for /f delims= %%i in ('dir /s /b test.txt') do (
- findstr /i /c:%str% %%i && start %%~dpi
- )
iv. 搜索到文本后直接打開本文的上上級(jí)路徑nclick="copycode($('code2'));">復(fù)制代碼
- @echo off
- set /p str=Please input the string:
- for /f delims= %%i in ('dir /s /b test.txt') do (
- findstr /i /c:%str% %%i && for %%j in (%%~dpi..) do (start %%~fsj)
- )
nclick="copycode($('code3'));">復(fù)制代碼
- @echo off
- set /p str=Please input the string:
- for /f delims= %%i in ('dir /s /b test.txt') do (
- findstr /i /c:%str% %%i && for %%j in (%%~dpi....) do (start %%~fsj)
- )

