Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to copy and delete files by VB.Net

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you the "VB.Net how to copy, delete files", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.Net how to copy, delete files" this article.

VB.Net language copies and deletes file codes:

Imports System.IO Imports System.IO.Directory'= 'implement a static method to copy everything under the specified folder to the destination folder' if the destination folder is read-only, an error will be reported. '= Public Shared Sub CopyDir (ByVal srcPath As String, ByVal aimPath As String) Try' checks whether the target directory ends with the directory division character\. If not, the added If aimPath (aimPath.Length-1) Path.DirectorySeparatorChar Then aimPath + = Path.DirectorySeparatorChar End If 'determines whether the source directory exists, and exits if it does not exist. If (Not Directory.Exists (srcPath)) Then Exit Sub 'determines whether the destination directory exists. If not, the newly created If (Not Directory.Exists (aimPath)) Then Directory.CreateDirectory (aimPath)' gets a list of files in the source directory, which is an array of files and directory paths. If you point to the files under the copy target file but do not include the directory, use the following method 'string [] fileList = Directory.GetFiles (srcPath) Dim fileList () As String = Directory.GetFileSystemEntries (srcPath) 'traversing all files and directories For Each FileName As String In fileList' is treated as a directory first. If this directory exists, recursively Copy the files under that directory If Directory.Exists (FileName) Then CopyDir (FileName, aimPath + Path.GetFileName (FileName)) 'otherwise direct Copy files Else File.Copy (FileName, aimPath + Path.GetFileName (FileName)) True) End If Next Catch ex As Exception MessageBox.Show (ex.ToString ()) End Try End Sub'= = 'implement a static method to Detele all the contents under the specified folder Cannot be restored after deletion. '= Public Shared Sub DeleteDir (ByVal aimPath As String) Try' checks whether the target directory ends with a directory segmentation character. If not, the added If (aimPath (aimPath.Length-1) Path.DirectorySeparatorChar) Then aimPath + = Path.DirectorySeparatorChar End If 'determines whether the directory to be deleted exists, and exits if it does not exist. If (Not Directory.Exists (aimPath)) Then Exit Sub 'gets a list of files in the source directory, which is an array of files and directory paths. If you point to the files under the Delete target file but do not include the directory, use the following method' string [] fileList = Directory.GetFiles (aimPath) Dim fileList () As String = Directory.GetFileSystemEntries (aimPath) 'traverses all files and directories For Each FileName As String In fileList If (Directory.Exists (FileName)) Then' is treated as a directory first, recursively Delete the files under the directory DeleteDir (aimPath + Path.GetFileName (FileName)) Else 'otherwise directly Delete files File.Delete (aimPath + Path.GetFileName (FileName)) End If Next' are deleted. Except for the folder System.IO.Directory.Delete (aimPath True) Catch ex As Exception MessageBox.Show (ex.ToString ()) End Try End Sub above are all the contents of the article "how to copy and delete files by VB.Net" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report