vb6中如何判断路径是文件还是目录?
How to determine a path is a file or directory in vb6?
我正在做一个项目,我需要从用户那里获取路径并在该路径上做一些事情,但我需要知道该路径是什么。我不能通过检查扩展名来做到这一点。因为也许文件没有扩展名。 php中是否有类似is_dir()
& is_file()
的函数?
检查原始字符串是否也是有效字符串。
Function FileOrFolder(strg As String)
Dim fs, FExists, DirExists
Set fs = CreateObject("Scripting.FileSystemObject")
FExists = fs.FileExists(strg)
DirExists = fs.folderexists(strg)
If FExists = True Then
FileOrFolder = "It's a file" '// file
ElseIf DirExists = True Then
FileOrFolder = "It's a folder" '// folder
Else
FileOrFolder = "Neither a file nor a folder" '// user string invalid
End If
End Function
你考虑过显而易见的事情吗?
If GetAttr(Path) And vbDirectory Then
MsgBox "Directory"
Else
MsgBox "Not directory"
End If
再使用一个函数:Dir$()
使用默认 vbNormal
属性参数 Dir$()
returns 如果路径名参数是目录,则为空字符串
Private Sub Command1_Click()
Dim strPath As String
Dim strFile As String
strPath = "c:\temp"
strFile = "c:\temp\pic.bmp"
Print strPath & " : " & CStr(IsDir(strPath))
Print strFile & " : " & CStr(IsDir(strFile))
End Sub
Private Function IsDir(strPath As String) As Boolean
If Len(Dir$(strPath, vbNormal)) = 0 Then
IsDir = True
Else
IsDir = False
End If
End Function
我正在做一个项目,我需要从用户那里获取路径并在该路径上做一些事情,但我需要知道该路径是什么。我不能通过检查扩展名来做到这一点。因为也许文件没有扩展名。 php中是否有类似is_dir()
& is_file()
的函数?
检查原始字符串是否也是有效字符串。
Function FileOrFolder(strg As String)
Dim fs, FExists, DirExists
Set fs = CreateObject("Scripting.FileSystemObject")
FExists = fs.FileExists(strg)
DirExists = fs.folderexists(strg)
If FExists = True Then
FileOrFolder = "It's a file" '// file
ElseIf DirExists = True Then
FileOrFolder = "It's a folder" '// folder
Else
FileOrFolder = "Neither a file nor a folder" '// user string invalid
End If
End Function
你考虑过显而易见的事情吗?
If GetAttr(Path) And vbDirectory Then
MsgBox "Directory"
Else
MsgBox "Not directory"
End If
再使用一个函数:Dir$()
使用默认 vbNormal
属性参数 Dir$()
returns 如果路径名参数是目录,则为空字符串
Private Sub Command1_Click()
Dim strPath As String
Dim strFile As String
strPath = "c:\temp"
strFile = "c:\temp\pic.bmp"
Print strPath & " : " & CStr(IsDir(strPath))
Print strFile & " : " & CStr(IsDir(strFile))
End Sub
Private Function IsDir(strPath As String) As Boolean
If Len(Dir$(strPath, vbNormal)) = 0 Then
IsDir = True
Else
IsDir = False
End If
End Function