VB.NET文件夹操作相关技巧分享

开发 后端
我们在这里为大家带来的有关VB.NET文件夹操作的具体方法主要分为对文件夹的复制以及删除这两种,希望能对又需要的朋友有所帮助。

编程人员利用VB.NET进行实际编程,可以轻松简便的完成各种功能。比如今天为大家介绍的VB.NET在对文件夹的操作上,就可以轻松的实现各种操作。下面就让我们一起来看看VB.NET文件夹操作相关应用技巧。

VB.NET文件夹操作之文件夹复制

  1. Function CopyDir()Function CopyDir
    (ByVal sourcePath As String, ByVal 
    targetPath As String) As Boolean  
  2. Try  
  3. '检查目标目录是否以目录分割字符结束,
    不是则添加  
  4. If Right(targetPath, 1) <> ""
     Then targetPath += ""  
  5. '判断目标目录是否存在,不存在则新建  
  6. If Not Directory.Exists(targetPath)
     Then Directory.CreateDirectory
    (targetPath)  
  7. ' 得到源目录的文件列表,该里面是包含
    文件以及目录路径的一个数组  
  8. Dim fileList As String() = 
    Directory.GetFileSystemEntries
    (sourcePath)  
  9. '遍历所有的文件和目录  
  10. For Each filepath As String In 
    fileList  
  11. '目录处理,递归  
  12. If (Directory.Exists(filepath)) Then  
  13. CopyDir(filepath, targetPath + 
    Path.GetFileName(filepath))  
  14. Else 

VB.NET文件夹操作之复制文件

  1. File.Copy(filepath, 
    targetPath 
    + Path.GetFileName
    (filepath), True)  
  2. End If  
  3. Next  
  4. Return True  
  5. Catch ex As Exception  
  6. Return False  
  7. End Try  
  8. End Function 

VB.NET文件夹操作之文件夹删除

  1. Function DelDir()Function DelDir
    (ByVal targetPath As String) 
    As Boolean  
  2. Try  
  3. '检查目标目录是否以目录分割字符结束,
    不是则添加  
  4. If Right(targetPath, 1) <> "
    " Then targetPath += ""  
  5. '得到源目录的文件列表,该里面是包
    含文件以及目录路径的一个数组  
  6. Dim fileList As String() = 
    Directory.GetFileSystemEntries
    (targetPath)  
  7. '遍历所有的文件和目录  
  8. For Each filepath As String 
    In fileList  
  9. '目录处理,递归  
  10. If (Directory.Exists(filepath)) Then  
  11. DelDir(targetPath + Path.GetFile
    Name(filepath))  
  12. Else  
  13. '删除文件  
  14. File.Delete(targetPath + Path.
    GetFileName(filepath))  
  15. End If  
  16. Next  
  17. '删除文件夹  
  18. System.IO.Directory.Delete
    (targetPath, True)  
  19. Return True  
  20. Catch ex As Exception  
  21. Return False  
  22. End Try  
  23. End Function 

VB.NET文件夹操作的相关应用方法就为大家介绍到这里。

【编辑推荐】

  1. VB.NET StringWriter基础概念详解
  2. VB.NET ArrayList具体功能详解
  3. VB.NET窗体打印代码解读
  4. VB.NET Format函数基础应用技巧详解
  5. VB.NET StructLayout特点详解
责任编辑:曹凯 来源: CSDN
相关推荐

2010-01-15 19:04:09

2010-01-13 15:33:40

VB.NET菜单项目

2009-10-27 11:03:16

VB.NET文件夹操作

2010-01-14 16:04:32

VB.NET显示时间

2010-01-15 15:10:43

VB.NET Stri

2010-01-18 16:33:57

VB.NET加密文件

2010-01-21 13:34:56

VB.NET删除文件夹

2010-01-07 13:40:50

VB.NET读取XML

2010-01-15 18:01:05

VB.NET结构化异常

2010-01-07 15:29:59

VB.NET表达式

2010-01-08 10:09:50

VB.NET注册表操作

2010-01-07 10:02:53

Flash控制VB.N

2009-10-27 08:56:22

VB.NET文件夹

2009-10-27 17:59:16

VB.NET删除文件夹

2010-01-15 13:52:42

VB.NET属性设置

2010-01-18 18:50:26

VB.NET鼠标手势

2010-01-18 14:08:29

VB.NET类型转换

2010-01-22 11:02:30

VB.NET创建新变量

2010-01-13 15:52:59

VB.NET浮动窗体

2010-01-07 17:24:12

VB.NET连接数据库
点赞
收藏

51CTO技术栈公众号