recursive search for string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: recursive search for string

#16 Post by doscode » 20 Apr 2012 08:39

abc0502:
notepad++ can save the results?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: recursive search for string

#17 Post by abc0502 » 20 Apr 2012 10:04

no unfortunately but if u wan't fast search then u have to use a program designed for searching or other fast programming language.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: recursive search for string

#18 Post by Squashman » 20 Apr 2012 10:21

doscode wrote:I just have rewrite what I had seen on dialog window of my local system. The size of whole structure has 14,9MB on disk. 15MB.

15 Megabytes worth of files shouldn't take 4 minutes to find a single file. Especially with the code Foxi is using. Something don't seem right with your setup.

What directory are you executing the script from?

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: recursive search for string

#19 Post by doscode » 20 Apr 2012 14:48

I execute the script from

P:\server\searchengine\

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: recursive search for string

#20 Post by doscode » 20 Apr 2012 14:51

abc0502:
Then I don't understand why you suggest Notepad++. I look(ed) for script to recover damaged files from backup.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: recursive search for string

#21 Post by foxidrive » 20 Apr 2012 20:12

Did you run the script overnight?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: recursive search for string

#22 Post by foxidrive » 20 Apr 2012 21:24

Try this: It will report each filename as it is tested.
When you said that it took 4 minutes to find one file, it might have tested 2000 files in that time.


Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.txt /b /s') do (
echo "%%a"
for /f "delims=" %%b in ('find "</coordinates>" ^<"%%a" ^|find /c /v "" ') do (
if %%b GTR 1 >>"found.txt" echo %%a
)
)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: recursive search for string

#23 Post by abc0502 » 21 Apr 2012 03:05

Try This i tested on 984 text file it took few seconds, replace the variable section with ur's:
This search for all the file types u choose then log there location in log.log file and use this log.log file to search for the string u choose so it make the search faster
if it worked with u i can make it looks better

Code: Select all

@echo off
cls
:: === Variables ======================
set "log=%temp%\log.log"
set "found=%userprofile%\desktop\Resulte.txt"
set "loc=D:"
set "type=*.txt"
set "string=text"
:: === Code =========================
if exist %log% Del /F /Q %log%
for /f "tokens=*" %%c in ('dir /b /s /a-d "%loc%\%type%"') do (
echo %%c >>"%log%"
)
For /f "tokens=*" %%g in (' findstr /m /F:%log% "%string%"') do echo %%g >>%found%

But it has one problem i can't make it check if the string exist more than once so if the string found at least once it put the file directory and name in the resulte file
try it and let me know ur results :)

Post Reply