.net IO 类库学习

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值