六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 74|回复: 0

.net IO 类库学习

[复制链接]

升级  10.67%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
66
 楼主| 发表于 2013-1-27 04:47:40 | 显示全部楼层 |阅读模式
Directory               可以实现目录的 复制、删除、移动、创建、改名
DirectoryInfo        可以实现目录的 复制、删除、移动、创建、改名

这两个类的区别是:Directory中的方法都是静态方法,如果你的操作是一次性的,那么可以考虑使用Directory,否则可以考虑使用DirectoryInfo.
注意:(默认情况下,所有的用户都将获得对新建目录的所有访问权限.)
下面是使用的例子:
Imports System
Imports System.Io
public class DirectoryInfo1
 
    Public Shared Sub Main()
        dim source as string="g:\mydoc\msdn学习笔记\io\tempdir1"
        dim destnation as string="g:\mydoc\msdn学习笔记\io\tempdir2"
        if Directory.Exists(source)=false then
              directory.CreateDirectory(source)
        end if
        if Directory.Exists(destnation) then
              directory.delete(destnation)
        end if
        Directory.Move(source,destnation)
        File.CreateText(destnation+"\myfile.txt")
  end sub
 
end class
注意:move方法可以实现改名功能。delete删除的目录不会放在回收站中
如果要使用DirectoryInfo类的话,必须先生成DirectoryInfo的实例,用目录名作为参数,例如
dim di as DirectoryInfo=new DirectoryInfo(“c:\Temp“)
其使用方法可以参考MSDN
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表