Hi All,
Am trying to check if a file exists using Dir$(filenamehere) and this works fine when I pass a filename to it by typign it in manually or even via a variable. However, if I read the filename from a text file using Textstream.Readline, it ALWAYS says the file exists, even when it doesnt.
I have tried to do a bit of debugging and have found that when I use the code below....
... and ask it to tell me what Dir$(Trackname) actually returns (with an INVALID FILE NAME) it shows nothing - As it's supposed to. (With a vlaid file name it returns the filename)
BUT if I read Trackname from a text file, when I ask it to return the value of Dir$(Trackname) I actually get the line of text from the file returned to me! Irrespective of whether it exists as a file or is even a valid file name! I've been trying to solve this all day and now my brain hurts... I'm guessing theres some sort of control character in the string that's returned from the text file, but I have no idea how to actually remove or even view such characters! That could be totally wrong of course... Any ideas?
TIA!
Am trying to check if a file exists using Dir$(filenamehere) and this works fine when I pass a filename to it by typign it in manually or even via a variable. However, if I read the filename from a text file using Textstream.Readline, it ALWAYS says the file exists, even when it doesnt.
I have tried to do a bit of debugging and have found that when I use the code below....
Code:
Private Sub Form_Load()
Dim Trackname As String
Trackname = "c:\test.txt"
If Dir$(Trackname) <> "" Then
Text1.Text = "File Exists"
Else
Text1.Text = "File DOESNT Exist"
End If
End Sub
... and ask it to tell me what Dir$(Trackname) actually returns (with an INVALID FILE NAME) it shows nothing - As it's supposed to. (With a vlaid file name it returns the filename)
BUT if I read Trackname from a text file, when I ask it to return the value of Dir$(Trackname) I actually get the line of text from the file returned to me! Irrespective of whether it exists as a file or is even a valid file name! I've been trying to solve this all day and now my brain hurts... I'm guessing theres some sort of control character in the string that's returned from the text file, but I have no idea how to actually remove or even view such characters! That could be totally wrong of course... Any ideas?
TIA!