我想将特定目录中的所有.dat文件(总是不同的名称)连接到一个文本文件中。有人能指出我正确的方向吗?
答案 0 :(得分:2)
您可以在VBA下运行dos:
Set oWSH = CreateObject("WScript.Shell")
oWSH.Run ("%comspec% /c copy c:\docs\conc\*.dat c:\docs\conc\onefile.txt")
如果文件有终结符,你将需要/ b开关,如果文件没有以返回结束,那么这些行将继续:
abc
defabc
def
答案 1 :(得分:1)
Sub a()
Dim spath As String
Dim intFileNum%, bytTemp As Byte
spath = "c:\kk\"
outFileNum = FreeFile
Open spath + "Outfile.out" For Binary Access Write As outFileNum
sdir = Dir$(spath & "*.dat", vbNormal)
Do Until LenB(sdir) = 0
inFileNum = FreeFile
Open spath + sdir For Binary Access Read Lock Read As inFileNum
Do While Not EOF(inFileNum)
Get inFileNum, , bytTemp
Put outFileNum, , bytTemp
Loop
Close inFileNum
sdir = Dir$
Loop
Close outFileNum
End Sub
唯一的诀窍是Dir$() has a weird iteration convention
HTH!
答案 2 :(得分:0)
我认为上面的例子可能比我下面的版本更快 但是在一个2 Mb音频文件上,上面花了31秒,参见下面的19 和Len = 1或100或1000没有区别。也许DOS喘息更快。我的文件可以是@ 128Kb波特率小时。
n=0
k=0
Do Until LenB(sdir) = 0
inFileNum = FreeFile
Open spath + sdir For Binary Access Read Lock Read As inFileNum Len = 1000
Do While Not EOF(inFileNum)
Get inFileNum, k, bytTemp
k=k+1
Put outFileNum, n, bytTemp
n=n+1
Loop