windows - Batch file giving File Not Found error -


been working on systematic file search script retrieve name of documents in directory, , sub directories contain determined search string. essentially, log search results. nice have search file names, that's not yet important.

code:

@echo off echo - search files in current directory, , subdirectories. echo - ignore case sensitivity. echo - search term within readable documents. set /p searchfilter=search filter:  set results=%cd%\results.txt echo searching... echo results: > "%results%" /f "usebackq tokens=*" %%i in (`dir /s/b/a:-d/o:e`) (     find /i "%searchfilter%" "%%~nxi" >nul && echo %%~nxi >> "%results%" ) echo search complete. pause 

run-down: system requests string user. then, system saves handle results file (thought fix problem, didn't). system filters files, excluding folders, directory, , sub directories, printing bare name of file (with extension), proceed scan each file search string, , save positive search results text file.

it seems on number of files, receive "file not found - " error, , need identifying it. guess, has trying find sub directory file without directory handle.

find /i "%searchfilter%" "%%i" >nul && echo %%~nxi >> "%results%" 

should fix problem, you've flagged yourself. if searching file named fred.txt exists in subdirectory mot in root of subtree scanned, you'll file not found error.

your choice whether echo name , extension results or whether echo full filename, of course. personally, i'd use `%%i , whole thing.

i'd change

for /f "usebackq tokens=*" %%i in (`dir /s/b/a:-d/o:e`) ( 

to

for /f "delims=" %%i in ('dir /s/b/a:-d/o:e') ( 

but that's matter of style in case.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -