dim ret as string
dim cn as adodb.connection
dim rs as adodb.recordsetset cn = new adodb.connection
cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\yourDB.mdb;Persist Security Info=False"
rs.open "select * from yourtable", cnret = dir(yourpath & "\*.txt")do until ret=""
rs.addnew
rs!filename = ret
open ret for input as #1
line input #1,ret
close #1
rs!firstLine = ret
rs.update
ret = dir()
looprs.close
set rs = nothing
cn.close
set cn = nothing

解决方案 »

  1.   

    上面朋友回答的思路和我一样
    不过不要用#1
    用freefile函数取一个值
      

  2.   

    TO:iceSpirit(冰之魂)
    对于用#1还是用FREEFILE都是一样的,只要你在前面用#1号打开过文件且还没有关闭该文件时就不能用#1号来打开文件了,如果前面没有用过则是行的!!
      

  3.   

    取得长文件名
    Public Function GetLongFilename (ByVal sShortName As String) As StringDim sLongName As String
    Dim sTemp As String
    Dim iSlashPos As Integer'Add \ to short name to prevent Instr from failing
    sShortName = sShortName & "\"'Start from 4 to ignore the "[Drive Letter]:\" characters
    iSlashPos = InStr(4, sShortName, "\")'Pull out each string between \ character for conversion
    While iSlashPos
    sTemp = Dir(Left$(sShortName, iSlashPos - 1), _
    vbNormal + vbHidden + vbSystem + vbDirectory)
    If sTemp = "" Then
    'Error 52 - Bad File Name or Number
    GetLongFilename = ""
    Exit Function
    End If
    sLongName = sLongName & "\" & sTemp
    iSlashPos = InStr(iSlashPos + 1, sShortName, "\")
    Wend'Prefix with the drive letter
    GetLongFilename = Left$(sShortName, 2) & sLongNameEnd Function
    下面是一个列出指定目录下所有符合要求的文件名的函数:
      Public Function AutoListFiles(ByVal sDirName As String,ByVal FileFilter As String ) As Boolean
      On Error GoTo RF_ERROR
      Dim sName As String, sFile As String, sExt As String
      Dim sDirList() As String, iDirNum As Integer, i As Integer
      ′首先枚举所有文件
      sFile = Dir(sDirName + FileFilter, vbNormal + vbArchive + vbHidden)
      Do While Len(sFile) >0
      sFile = UCase(Trim(sFile))
      ′在此处可以将 sFile 加入到一个 Text 控件...
      sFile = Dir ′下一个文件
      Loop
      iDirNum = 0
      sName = Dir(sDirName + ″*.*″, vbDirectory + vbNormal)
      Do While Len(sName) >0
      If sName <> ″.″ And sName <> ″..″ Then
      iDirNum = iDirNum + 1
      ReDim Preserve sDirList(1 To iDirNum)
      sDirList(iDirNum) = sDirName + sName + ″\″
      End If
      sName = Dir ′下一个目录
      Loop
      For i = 1 To iDirNum
      AutoListFiles sDirList(i) ′递归调用
      Next
      End If
      RF_EXIT:
      AutoListFiles = True
      Exit Function
      RF_ERROR:
      MsgBox Err.Description, vbCritical, ″″
      Resume RF_EXIT
      End Function
      调用上述函数的示例:
      AutoListFiles(″C:\″,″*.TMP″)
      之所以采用上述先处理文件,再处理子目录,一是思路较清晰,另外也有模仿 Prolog 语言中的“尾递归”的想法,当然,VB中是不支持尾递归的。