发新话题
打印

[API] 谁能帮我把这个实例改一下啊?

谁能帮我把这个实例改一下啊?

谁能帮我把这个实例改一下啊?
我想把正在扫描的路径放到LABEL中(如图),并且在找到的*.EXE中 打开查找某些字符。
Option Explicit
Public Declare Function FindFirstFile Lib "kernel32" Alias
"FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias
"FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Const MAX_PATH = 260
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
'自定义数据类型FILETIME和WIN32_FIND_DATA的定义
Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type
Private Sub finfiles(tCurrentdir As String)
    Dim itmX As ListItem
    Dim tFindData As WIN32_FIND_DATA
    Dim strFileName As String
    Dim lHandle As Long
    Dim CountFolder As Integer
    Dim CountFiles As Integer
    CountFolder = 0
    CountFiles = 0
    ListView1.ListItems.Clear
    lHandle = FindFirstFile(tCurrentdir & "\*.*", tFindData)
    If lHandle = 0 Then
       Set itmX = ListView1.ListItems.Add(, , strFileName & "找不到文件
")
       Exit Sub
    End If
   strFileName = fDelInvaildChr(tFindData.cFileName)
   Do While True
        tFindData.cFileName = ""
        If FindNextFile(lHandle, tFindData) = 0 Then
            FindClose (lHandle)
            Exit Do
        Else
            strFileName = fDelInvaildChr(tFindData.cFileName)
            If tFindData.dwFileAttributes = &H10 Then
                If strFileName <> "." And strFileName <> "." Then
                    Set itmX = ListView1.ListItems.Add(, , strFileName)
                    itmX.SmallIcon = 1
                    CountFolder = CountFolder + 1
                End If
            Else
                Debug.Print InStr(LCase(Right(strFileName, 3)),
ExtendFileName)
                If InStr(ExtendFileName, LCase(Right(strFileName, 3)))
> 0 Then
               Set itmX = ListView1.ListItems.Add(, , strFileName)
                    itmX.SubItems(1) = CStr(FileLen(tCurrentdir & "\" &
strFileName))
                    itmX.SmallIcon = 2
                    itmX.SubItems(2) = FileDateTime(tCurrentdir & "\" &
strFileName)
                    CountFiles = CountFiles + 1
                End If
            End If
        End If
    Loop
    ListView1.Sorted = True
    ListView1.SortKey = 1
    StatusBar1.Panels(2).Text = CurrentDir
    StatusBar1.Panels(3).Text = "文件夹:" & CountFolder & " 文件:" & CountFiles
End Sub

TOP

你的代码太垃圾了,文件操作还用API?
可以使用两种方案
1、使用VB的函数,请参见VB的文件函数
   参考Dir 、FileLen 、FileDateTime等函数
2、使用文件对象
   参考FileSystemObject对象
以上内容MSDN中都有详细的介绍
换个头像,看见广告就眼红,直接封ID。

TOP

好长,先调试下看是那部分的问题吧

TOP

发新话题