Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi Friends,
I am kinda new to Batch file programming.
I have few text files in a folder. (eg: mp3_1.txt mp3_2.txt mp3_3.txt etc etc). All these text files contains some mp3 songs file names in each line.I want to search a specific string in all these files and I want to display the matching lines as
mp3_1.txt
<tab> line1
<tab> line32
<tab> line45mp3_2.txt
<tab> line2
<tab> line6I dont want other files in the folder to be displayed. (only the file contaning the string should be displayed)
Can anyone guide me in this regard?

I think you are doing it backwards. The mp3 text files entries should be all added to a database. Then indexed by title, artist, location, etc. acccording by how you want it accessed.

thanks for the quick reply.
i think that will solve a big problem. bt if i want to have these files seperate, is there any solution?

You still can have the text files separate. The database will contain the information that you consider important or a link back to the text file.

Another method is to use a utility like GREP. It will do the seach almost exactly as you require except for the tab.
grep options string *.txt

vbscript
Set objFS = CreateObject("Scripting.FileSystemObject") strFolder = "c:\test" strSearch = "test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files strFileName =strFile.Name strFilePath = strFile.Path strFileExt = objFS.GetExtensionName(strFile) If strFileExt = "txt" Then Set objFile = objFS.OpenTextFile(strFile) s="" f=0 Do Until objFile.AtEndOfLine linenum=objFile.Line strLine = objFile.ReadLine If InStr(strLine,strSearch) > 0 Then s = s & strLine & "-> line: " & linenum f=1 End If Loop If f=1 Then WScript.Echo strFileName WScript.Echo vbTab & s End If objFile.Close End If Nextsave as myscript.vbs and on command line
c:\test> cscript /nologo myscript.vbs

wow.. thank you for the code. it worked with me. I have also tried to do it using bat file. Well, i came up with a solution today.
I am putting the code here.echo.
set/p cho=Please Enter Keyword:
cd "CD Content"
echo.
echo Search Results for - %cho%
echo.
for %%f in (*.*) do (
findstr /i "%cho%" "%%f" > found.cdtxt
for %%t in (found.cdtxt) do (
if %%~zt GTR 0 (
echo.
echo %%f
for /F "tokens=* delims=" %%t in (found.cdtxt) do (
echo %%t
)
)
)
)
echo.
pause
del found.cdtxt
cd ..thank you guys for helping me with the code.

![]() |
i want create msi file fo...
|
batch to rename txt file ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |