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