如:调用函数    loadleader(变量1,变量2)
   现我要判断变量1为文件还是文件夹?(在函数中判断)

解决方案 »

  1.   

    Option ExplicitPrivate Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As LongConst INVALID_HANDLE_VALUE = -1
    Const FILE_ATTRIBUTE_DIRECTORY = &H10
    Public Function Test(ByVal FilePath As String)    Dim lRet         As Long
        
        lRet = GetFileAttributes(FilePath)
        
        If lRet = INVALID_HANDLE_VALUE Then
            MsgBox "Error"
        ElseIf lRet And FILE_ATTRIBUTE_DIRECTORY Then
            MsgBox "Fold"
        Else
            MsgBox "File"
        End If
        
        
    End Function=============================
    Option ExplicitPrivate Sub Dir1_Click()
        Test Dir1.path
    End SubPrivate Sub File1_Click()
        Test File1.FileName
    End Sub
      

  2.   

    在c:新建文件夹ttt.ttt和文件tt.tt
    Private Sub Command1_Click()
        CheckAttr "c:\ttt.ttt"
    End SubPrivate Sub Command2_Click()
        CheckAttr "c:\tt.tt"
    End Sub
    Public Function CheckAttr(strName As String)
        If Dir(strName, vbNormal) <> "" Then
            MsgBox strName & " 是文件"
        ElseIf Dir(strName, vbDirectory) <> "" Then
            MsgBox strName & " 是文件夹"
        End If
    End Function