Skip to content

Commit 66acc0d

Browse files
committed
Update CSVTextStream.cls
1 parent bbfa901 commit 66acc0d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/CSVTextStream.cls

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ Public Function DetectEncoding(filePath As String) As String
236236
fileNum = FreeFile
237237
Open filePath For Binary Access Read As #fileNum
238238

239+
If LOF(fileNum) = 0 Then
240+
DetectEncoding = "ANSI"
241+
Exit Function
242+
End If
239243
' Read up to the first 1024 bytes
240244
byteCount = IIf(LOF(fileNum) < 1024, LOF(fileNum), 1024)
241245
ReDim byteData(0 To byteCount - 1)
@@ -429,12 +433,12 @@ End Sub
429433
Public Sub OpenStream(filePath As String)
430434
Attribute OpenStream.VB_Description = "Opens a stream over a text file."
431435
If P_PATH <> filePath Then
436+
CreateSubFolders filePath
432437
If P_AUTODETECTENCODING Then
433438
P_DETECTEDENCODING = DetectEncoding(filePath)
434439
P_UTF8ENCODED = (P_DETECTEDENCODING = "UTF-8")
435440
End If
436441
FileHandled = FreeFile
437-
CreateSubFolders filePath
438442
Open filePath For Binary As #FileHandled
439443
P_ISOPENSTREAM = True
440444
P_STREAMLENGTH = LOF(FileHandled)

0 commit comments

Comments
 (0)