FSO ReadLine and Instr - Postet den (1911 Views)
Advanced Member
Carefree
Innlegg: 4224
4224
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
%>
   
 Sidestørrelse 
Postet den
Snitz Forums Admin
ruirib
Innlegg: 26364
26364
I think the correct way to test for a InStr match is to check if it returns a value > 0.
Postet den
Average Member
cripto9t
Innlegg: 881
881
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
%>
    _-/Cripto9t\-_
Postet den
Advanced Member
Carefree
Innlegg: 4224
4224
Apparently the necessary ingredient was trimming the string. It works with/without a comparison to > 0 as long as it's trimmed first. Thanks.
Postet den
Average Member
cripto9t
Innlegg: 881
881
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.
    _-/Cripto9t\-_
 
Du må legge inn en melding