Skip to content

Commit 97be578

Browse files
committed
Bug fixed: subfolders were not managed correctly.
1 parent f8666a4 commit 97be578

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/CSVTextStream.cls

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ Attribute CloseStream.VB_Description = "Closes the current text file stream."
170170
P_PATH = vbNullString
171171
End If
172172
End Sub
173+
Private Sub CreateSubFolders(FullFilePath As String)
174+
Dim cPath As String
175+
Dim SubFolders() As String
176+
Dim j As Long
177+
178+
SubFolders() = Split(FullFilePath, "\")
179+
cPath = SubFolders(LBound(SubFolders))
180+
For j = LBound(SubFolders) + 1 To UBound(SubFolders) - 1
181+
cPath = cPath & "\" & SubFolders(j)
182+
If Not FolderExists(cPath) Then
183+
MkDir cPath 'Create the subdirectory
184+
End If
185+
Next j
186+
End Sub
173187
Private Sub DoubleBufferSize()
174188
Dim LCSt As Long
175189
P_BUFFERSIZE = 2 * P_BUFFERSIZE
@@ -238,6 +252,9 @@ Private Sub FindEOLcharacter()
238252
End If
239253
Seek #FileHandled, CorrectedPos
240254
End Sub
255+
Private Function FolderExists(ByVal filePath As String) As Boolean
256+
FolderExists = CBool(LenB(Dir(filePath, vbDirectory)))
257+
End Function
241258
Private Sub GoBackToLineBreak()
242259
Do
243260
BufferMark = BufferMark - 2
@@ -278,6 +295,7 @@ Public Sub OpenStream(filePath As String)
278295
Attribute OpenStream.VB_Description = "Opens a stream over a text file."
279296
If P_PATH <> filePath Then
280297
FileHandled = FreeFile
298+
CreateSubFolders filePath
281299
Open filePath For Binary As #FileHandled
282300
P_ISOPENSTREAM = True
283301
P_STREAMLENGTH = LOF(FileHandled)

0 commit comments

Comments
 (0)