VB.Net判断目录或文件是否存在的代码

前端之家收集整理的这篇文章主要介绍了VB.Net判断目录或文件是否存在的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
If Boo_DirExist("F:/dir/") Then
MsgBox("存在F:/dir/目录")
Else
MsgBox("不存在F:/dir/目录")
End If
If Boo_FileExist("F:/file.txt") Then
MsgBox("存在F:/file.txt文件")
Else
MsgBox("不存在F:/file.txt文件")
End If
End Sub

'判断目录是否存在的函数,传入String值,返回Boolean值

Private Function Boo_DirExist(ByVal Str_Path As String) As Boolean
Boo_DirExist = System.IO.Directory.Exists(Str_Path)
End Function

'判断文件是否存在的函数,返回Boolean值

Private Function Boo_FileExist(ByVal Str_File As String) As Boolean Boo_FileExist = System.IO.File.Exists(Str_File) End FunctionEnd Class

原文链接:https://www.f2er.com/vb/263252.html

猜你在找的VB相关文章