朋友请进!在函数中怎样判断传过来的变量是文件还是文件夹?

myhgyp 2003-08-06 11:15:34
如:调用函数 loadleader(变量1,变量2)
现我要判断变量1为文件还是文件夹?(在函数中判断)
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gpo2002 2003-08-06
  • 打赏
  • 举报
回复
Option Explicit

Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long

Const 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 Explicit

Private Sub Dir1_Click()
Test Dir1.path
End Sub

Private Sub File1_Click()
Test File1.FileName
End Sub
lxqlogo0 2003-08-06
  • 打赏
  • 举报
回复
用 Dir()函数判断
lxcc 2003-08-06
  • 打赏
  • 举报
回复
在c:新建文件夹ttt.ttt和文件tt.tt
Private Sub Command1_Click()
CheckAttr "c:\ttt.ttt"
End Sub

Private 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

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧