Below is the code.
I'm not a developer so I can't explain what it does in any other way.
Option Compare Database
Public Const d = "\\Server\folder\Folder\"
Public Const FTP_dir = "\\Server\folder\Folder\"
Public Const batchlog = "\\Server\folder\Folder\"
Option Explicit
Public Function do_dir()
On Error GoTo LError
Dim a As Variant
Open batchlog + "XXXXXXX" + CStr(Date) + ".log" For Append As #3 Print #3, "Start: " + CStr(Now())
a = Dir(d + "*_XXXXX*.tmp")
If Not a = "" Then Call do_file(a) Else GoTo LExit
Nxt: a = Dir
If Not a = "" Then Call do_file(a) Else GoTo LExit GoTo Nxt
LExit:
Print #3, "End: " + CStr(Now())
Close #3
Exit Function
LError:
Print #3, "Error: " + CStr(Err.Number) + " " + Err.Description
Resume LExit
End Function
Public Function do_file(a_tmp As Variant) Dim rec, a_txt As String Print #3, (a_tmp + " to be handled") a_txt = Left(a_tmp, Len(a_tmp) - 3) + "txt"
Open d + a_tmp For Input Access Read Lock Write As #1 ' Open file.
'If EOF(1) Then GoTo Empty_File
Open d + a_txt For Output As #2 ' Open file.
' Open file for output.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, rec
rec = Replace(rec, """", "")
Print #2, rec
Loop
Print #3, (a_txt + " created.""'s removed") Close #2
'Empty_File:
Close #1
Call distrib_file(a_txt, a_tmp)
End Function
Function distrib_file(a_txt, a_tmp)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
fs.copyfile (d + a_txt), d + "history/"
Print #3, (a_txt + " copied to history catalog")
fs.copyfile (d + a_txt), FTP_dir
'COMMENT to PREVENT COPY IN TEST'
Print #3, (a_txt + " copied to FTP catalog") 'fs.copyfile (d + a_txt), "X:\Folder\Folder\Folder"
fs.deletefile (d + a_txt)
Print #3, (d + a_txt + " deleted")
fs.deletefile (d + a_tmp)
Print #3, (d + a_tmp + " deleted")
End Function
Public Function quit()
DoCmd.quit