【发布时间】:2019-01-31 08:04:16
【问题描述】:
我需要使用固定 (.txt) 导入规范将一堆文件导入访问。但是,虽然这些文件可以在记事本中很好地打开,但它们不是 .txt 文件,因此导入失败。
原始文件已压缩。我已经有下面的代码(提取的和不完整的)来解压缩它们并将它们放在一个文件夹中。每次导入后,解压后的文件都会被删除以释放空间。
If LCase(Right(fil.Name, 3)) = "zip" Then
Status "Unzip file '" & fil.Name & "'..."
currentISO = Left(fil.Name, 2)
UnZipFiles iZip, fil.Path
iTimeEnlapsed = 0
'Pause until the file is completely extracted
Do Until fso.GetFolder(iZip).Files.Count > 0
Call Sleep(Int(fil.Size / (2 * 20)))
'If unzip failed after 15sec it will be invoked again
iTimeEnlapsed = iTimeEnlapsed + 1000
If iTimeEnlapsed > 50000 Then
If MsgBox("UnZip Error: " & fil.Name & vbCrLf & vbCrLf & "Do you want to SKIP this file and resume IMPORT process?", vbYesNo + vbQuestion, "UNZIP Errot - Resume ") = vbYes Then
Exit Do
End If
UnZipFiles iZip, fil.Path
iTimeEnlapsed = 0
Exit Do
End If
Loop
For Each fil2 In fso.GetFolder(iZip).Files
'Import the files (after converting them to .txt)
DoCmd.TransferText acImportFixed, "Daily_Import", "Import_Data_Dump", fil.Path
Kill fil2
Next fil2
Set fil2 = Nothing
Else
End If
在上面的代码之后(对于每个 fil2),导入是从文件路径(很容易更改)完成的。但是,如果我的文件不以 .txt 结尾,这将不起作用。它们都是 XXXXX 而不是 XXXXX.txt,它们没有文件扩展名
【问题讨论】: