FileSystemObject error when the file names has special letters (1 Viewer)

Ocicek

New member
Local time
Today, 08:29
Joined
Jan 19, 2021
Messages
25
No problem. This is one of those good posts where I learn more from answering than the OP.
Hello Majp

I hope you're well since we didn't see communicated:) After working with this code for a long time, my friends warned me about something. The problem is, the code skips importing some files in the folder. It imports the file it skipped on the next attempt, but skips the file it imported in the previous transfer. What could be the reason for this?

My code is below and I'm sending a couple of sample files attached.

Can you please help me about the issue?

Code:
Function Mb_Al_1()


Dim FSO As Object, objFolder As Object, objFile As Object
Dim OldName As String
Dim NewName As String
Dim FolderPath As String
Dim I As Integer
Dim j As Integer
Set FSO = CreateObject("Scripting.FileSystemObject")



'Set objFile = New Scripting.File
On Error GoTo errlog
FolderPath = [Forms]![Payl_Okuma_Veri_Aktarimi_Ana_Form]![MB_Klasor_Konumu] & "\"
Set objFolder = FSO.GetFolder(FolderPath)
For Each objFile In objFolder.Files

  If Right(objFile.Name, 3) = "csv" Then
    OldName = objFile.Name
    j = j + 1
  
    NewName = "Import_" & Format(Date, "yyyymmdd") & "_" & j & ".csv"
  
   ' For I = 1 To Len(NewName)
   '   Debug.Print (Mid(NewName, I, 1)) & " " & Asc(Mid(NewName, I, 1))
   ' Next I
    Debug.Print OldName & " " & NewName
    Debug.Print
    'Choose to copy
    FSO.CopyFile FolderPath & "\" & OldName, FolderPath & "\" & NewName
    'choose to rename
    'FSO.MoveFile FolderPath & "\" & OldName, FolderPath & "\" & NewName
    DoCmd.TransferText acImportDelim, "MB3", "MB_Sheet_Ham", FolderPath & "\" & NewName, False
    FSO.DeleteFile FolderPath & "\" & NewName
  End If
Next objFile
Exit Function
errlog:
  Debug.Print Err.Number & " " & Err.Description & " new name: " & NewName
 
Resume Next
 
Set objFile = Nothing
Set objFolder = Nothing
Set FSO = Nothing

End Function
 

Attachments

  • MB_Archive.zip
    825.1 KB · Views: 1

Users who are viewing this thread

Top Bottom