---
title: "VB.Net检查文件是否存在及删除文件"
author: "kiki1120"
date: "2012-08-23T16:20:05Z"
tags: []
categories: ["编程语言"]
slug: "vb-net"
draft: false
lastmod: "2013-03-12T21:56:24Z"
id: 1659967
url: "https://mimmy.iteye.com/blog/1659967"
---

Dim FileExists As Boolean

Dim filePath = "D:\\Book1.xls"

fileExists = My.Computer.FileSystem.FileExists(filePath)

If fileExists = False Then

    MsgBox("文件不存在")

Else

    '文件存在则删除文件

    My.Computer.FileSystem.DeleteFile(filePath, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)

End If