FSO ReadLine and Instr

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/69096?pagenum=1
05 November 2025, 09:24

Topic


Carefree
FSO ReadLine and Instr
26 December 2009, 00:53


I want to extract just mp3 files from a playlist using FSO. I thought this would do it, but it returns all lines. Any clue?
Code:

<%
dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Const FSOForReading = 1
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("c:\Playlist.m3u", FSOForReading)
Do while not objTextStream.AtEndOfStream
if instr(objTextStream.ReadLine, ".mp3") then
Response.Write objTextStream.ReadLine & "<br>"
end if
Loop
objTextStream.Close
set objTextStream = Nothing
%>

 

Replies ...


ruirib
26 December 2009, 08:26


I think the correct way to test for a InStr match is to check if it returns a value > 0.
cripto9t
26 December 2009, 12:02


What Rui said and i don't know if you can check the line like that.
Try this if you haven't got it working yet
Code:
<%
dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Const FSOForReading = 1
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("c:\Playlist.m3u", FSOForReading)
dim tmpStr Do while not objTextStream.AtEndOfStream
tmpStr = trim(objTextStream.Readline)
if instr(tmpStr,".mp3") > 0 then
Response.Write tmpStr & "<br>"
end if
Loop
objTextStream.Close
set objTextStream = Nothing
%>
Carefree
26 December 2009, 12:33


Apparently the necessary ingredient was trimming the string. It works with/without a comparison to > 0 as long as it's trimmed first. Thanks.
cripto9t
26 December 2009, 15:34


yep default comparison for inStr is binary. Just looked it up smile.
I trim all text out of habit. Been burned too many times by not using it smile.
© 2000-2021 Snitz™ Communications