实现功能:
VB中操作一个文件,确定文件在哪个目录下
有专用的API函数么
如果没有,如何实现?
谢谢了

解决方案 »

  1.   

    Public Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As LongPublic Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
    Dim iNull As Integer
    Dim lResult As Long
    Dim sBuffer As String
        On Error GoTo L_FILEFINDERROR
        sBuffer = String$(1024, 0)
        '查找文件
    lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
        '如果文件找到,将返回字符串后续的空格删除
        '否则返回一个空字符串
        If lResult Then
            iNull = InStr(sBuffer, vbNullChar)
            If Not iNull Then
                sBuffer = Left$(sBuffer, iNull - 1)
            End If
            sysFileFind = sBuffer
            Else
                sysFileFind = ""
        End If
    Exit Function
    L_FILEFINDERROR:
    MsgBox "查找文件过程中遇到错误!", vbInformation, "查找文件错误"
    sysFileFind = Format(Err.Number) & " - " & Err.Description
    End Function
    Private Sub Form_Load()
    MsgBox sysFileFind("c:\", "findfiles.txt")End Sub
      

  2.   

    谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢各位朋友,非常感谢可能大家没有看明白我的意思吧
    我得意思就是说
    就是说
    我编译完一个VB程序后
    一运行此文件
    她就会弹出一MsbBox
    告诉我她现在在我的硬盘中的哪里
    谢谢各位了