就是我用dir命令从ftp当前目录下列出所有的文件和文件夹,之后我用GetChunk从缓冲区读取列出的文件和文件夹,它返回给我的是一个字符串,其中包括列出的文件和文件夹,如:1.txt2.txt3.txtmydir/新建文件夹/,其中1.txt、2.txt、3.txt是文件,mydir、新建文件夹是文件夹我的问题是怎样从它返回的字符串中将其包括的各文件和各文件夹分别给剥离出来,

解决方案 »

  1.   

    Private strFilePath(250) As String              '搜索所有MP4文件
      For i = 0 To 24
        strFilePath(0) = Chr(99 + i) & ":\DVR-VIDEO"
        pStrFilePath = 0
        DoEvents
        Do
          FindFilesApi strFilePath(pStrFilePath), ".mp4"
          pStrFilePath = pStrFilePath - 1
        Loop Until pStrFilePath = -1
      Next
    Sub FindFilesApi(St As String, FileSpec As String)
      Dim FindData As WIN32_FIND_DATA
      Dim FindHandle As Long          '查找文件的函数句柄
      Dim DirPath As String           '本次检索的路径
      Dim FindNextHandle As Long
      Dim strTmp As String            '临时变量
      Dim DirIsNull As Boolean        '目录是否为空
      
      On Error GoTo Deal
      DirIsNull = True
      DirPath = UCase(Trim$(St))
      FileSpec = UCase(FileSpec)
      
      If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\"
      FindData.cFileName = Space$(MAX_PATH)     '用空格填充,方便使用Trim函数去空格
      FindHandle = FindFirstFile(DirPath & "*.*", FindData)   '进行第一次查找
      If FindHandle = -1 Then Exit Sub        '如果失败,说明路径不存在
      If FindHandle <> 0 Then
        If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then  '如果是路径
          If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
            '保存进String缓存中去
            DirIsNull = False
            strTmp = Trim$(FindData.cFileName)
            strFilePath(pStrFilePath) = DirPath & Left(strTmp, Len(strTmp) - 1) & "\"
            pStrFilePath = pStrFilePath + 1
          End If
        Else      '否则是文件
          strTmp = UCase$(Trim$(FindData.cFileName))
          If InStr(strTmp, FileSpec) > 0 Then
            Call GetMintoDB(FindData, DirPath)    '保存到自定义数组中去
            DirIsNull = False
          End If
        End If
      End If
      If FindHandle <> 0 Then
        Do
          DoEvents
          FindData.cFileName = Space$(MAX_PATH)
          FindNextHandle = FindNextFile(FindHandle, FindData)
          If FindNextHandle <> 0 Then
            If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
              If Left$(FindData.cFileName, 1) <> "." And Left$(FindData.cFileName, 2) <> ".." Then
                DirIsNull = False
                strTmp = Trim$(FindData.cFileName)
                strFilePath(pStrFilePath) = DirPath & Left(strTmp, Len(strTmp) - 1) & "\"
                pStrFilePath = pStrFilePath + 1
              End If
            Else
              strTmp = UCase$(Trim$(FindData.cFileName))
              If InStr(strTmp, FileSpec) > 0 Then
                DirIsNull = False
                Call GetMintoDB(FindData, DirPath)
              End If
            End If
          Else
            Exit Do
          End If
        Loop
      End If
      Call FindClose(FindHandle)
      If DirIsNull Then RmDir DirPath       '删除空目录
      Exit Sub
    Deal:
      
    End Sub