I've been using this routine for a long time:
Today it stumbled on the following filename:
"Adding hotkey to Semen's - Josés shortcut code - PowerBASIC Peer Support Forums.mht"
It seems to me that the file OPENs with no problem (the ERR test that follows the OPEN does not report an error).
But LOF() is returning 0 for a 480K file. Thus temp incorrectly gets set as a 0-length string.
Suspicious of the apostrophe and the accented e, I copied the file with a new name (no special chars) and it works fine, so I know it isn't the file content.
But why does OPEN not have a problem, and LOF does? (Or is OPEN having a problem that I'm not catching?)
I'm probably forgetting something obvious (to you)... Can anyone else see it?
Thanks,
-John
P.S. I'm continuing to test: DIR$ returns the name with the accented e changed to (what appears to be) a comma...
I have a sinking feeling that I'm back in the realm of DOS vs OEM character sets, so let me make this point right away: I am not creating the filenames. I have no control over what's on the drive. If the file was saved via some other program or a web browser or a user with a mean streak and it contains non-standard characters, that's what I've got to deal with. I have to be able to recognize such situations. But HOW?
... I still don't understand: should OPEN be reporting an error?
-jhm
Code:
Function GrabFileAsString (ByVal FilName As String) As String 'Opens the file and returns it in a string... Local InBuf As Long, InpLen As Quad, temp As String FilName = Trim$(FilName, $Dq) 'just to be sure... InBuf = FreeFile On Error Resume Next Open FilName For Binary As #InBuf If Err Then Function = "" ' Exit Function End If On Error GoTo 0 InpLen = Lof(InBuf) Get$ #InBuf, InpLen, temp Close #InBuf Function = temp End Function
"Adding hotkey to Semen's - Josés shortcut code - PowerBASIC Peer Support Forums.mht"
It seems to me that the file OPENs with no problem (the ERR test that follows the OPEN does not report an error).
But LOF() is returning 0 for a 480K file. Thus temp incorrectly gets set as a 0-length string.
Suspicious of the apostrophe and the accented e, I copied the file with a new name (no special chars) and it works fine, so I know it isn't the file content.
But why does OPEN not have a problem, and LOF does? (Or is OPEN having a problem that I'm not catching?)
I'm probably forgetting something obvious (to you)... Can anyone else see it?
Thanks,
-John
P.S. I'm continuing to test: DIR$ returns the name with the accented e changed to (what appears to be) a comma...
I have a sinking feeling that I'm back in the realm of DOS vs OEM character sets, so let me make this point right away: I am not creating the filenames. I have no control over what's on the drive. If the file was saved via some other program or a web browser or a user with a mean streak and it contains non-standard characters, that's what I've got to deal with. I have to be able to recognize such situations. But HOW?
... I still don't understand: should OPEN be reporting an error?
-jhm
Comment