文件测试!

happyfly2003 2003-12-02 11:15:13
如何判断一个文件在系统中是否存在或是有意义呢?
...全文
47 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyanghe111 2003-12-02
  • 打赏
  • 举报
回复
用dir函数或者FileSystemObject对象的FileExist方法就行
jpinglee 2003-12-02
  • 打赏
  • 举报
回复
//如何判断一个文件在系统中是否存在?

判断一个文件或者文件夹FileOrFolderName在path下是否存在?
(工程中引用Microsoft Scriptiong Runtime)
Public Function IfExistFileOrFolder(path As String, FileOrFolderName As String) As Boolean
Dim fso As New FileSystemObject
Dim folder As folder
Dim subfolder As folder
Dim file As file
Set folder = fso.GetFolder(path)
IfExistFileOrFolder = False

If folder.Files.Count > 0 Then
For Each file In folder.Files
If file.Name = FileOrFolderName Then
IfExistFileOrFolder = True
Exit Function
End If
Next file
End If

If folder.SubFolders.Count > 0 Then
For Each subfolder In folder.SubFolders
If subfolder.Name = FileOrFolderName Then
IfExistFileOrFolder = True
Exit Function
Else
Call IfExistFileOrFolder(subfolder.path, True)
End If
Next subfolder
End If

End Function

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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