×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net Windows文件系统


VB.Net  文件处理VB.Net 文件处理


VB.Net允许您使用各种目录和文件相关的类,如DirectoryInfo类和FileInfo类处理目录和文件。

DirectoryInfo类

DirectoryInfo类是从FileSystemInfo类派生的。 它有各种方法来创建,移动和浏览目录和子目录。 此类不能继承。

以下是DirectoryInfo类的一些常用属性:

S.N 属性名称和说明
1

Attributes

Gets the attributes for the current file or directory.

获取当前文件或目录的属性。

2

CreationTime

Gets the creation time of the current file or directory.

获取当前文件或目录的创建时间。

3

Exists

Gets a Boolean value indicating whether the directory exists.

获取指示该目录是否存在的布尔值。

4

Extension

Gets the string representing the file extension.

获取表示文件扩展名的字符串。

5

FullName

Gets the full path of the directory or file.

获取目录或文件的完整路径。

6

LastAccessTime

Gets the time the current file or directory was last accessed.

获取上次访问当前文件或目录的时间。

7

Name

Gets the name of this DirectoryInfo instance.

获取此DirectoryInfo实例的名称。

以下是DirectoryInfo类的一些常用方法:

S.N 方法名称和用途
1

Public Sub Create

Creates a directory.

创建目录。

2

Public Function CreateSubdirectory (path As String ) As DirectoryInfo

Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.

在指定的路径上创建子目录或子目录。 指定的路径可以相对于DirectoryInfo类的此实例。

3

Public Overrides Sub Delete

Deletes this DirectoryInfo if it is empty.

如果DirectoryInfo为空,则删除它。

4

Public Function GetDirectories As DirectoryInfo()

Returns the subdirectories of the current directory.

返回当前目录的子目录。

5

Public Function GetFiles As FileInfo()

Returns a file list from the current directory.

从当前目录返回文件列表。

有关属性和方法的完整列表,请访问Microsoft的文档。

FileInfo类

FileInfo类是从FileSystemInfo类派生的。 它具有用于创建,复制,删除,移动和打开文件的属性和实例方法,并且有助于创建FileStream对象。 此类不能继承。

以下是FileInfo类的一些常用属性:

S.N 属性名称和说明
1

Attributes

Gets the attributes for the current file.

获取当前文件的属性。

2

CreationTime

Gets the creation time of the current file.

获取当前文件的创建时间。

3

Directory

Gets an instance of the directory, which the file belongs to.

获取该文件所属的目录的实例。

4

Exists

Gets a Boolean value indicating whether the file exists.

获取指示文件是否存在的布尔值。

5

Extension

Gets the string representing the file extension.

获取表示文件扩展名的字符串。

6

FullName

Gets the full path of the file.

获取文件的完整路径。

7

LastAccessTime

Gets the time the current file was last accessed.

获取当前文件上次访问的时间。

8

LastWriteTime

Gets the time of the last written activity of the file.

获取文件的上次写入活动的时间。

9

Length

Gets the size, in bytes, of the current file.

获取当前文件的大小(以字节为单位)。

10

Name

Gets the name of the file.

获取文件的名称。


以下是FileInfo类的一些常用方法:

S.N 方法名称和用途
1

Public Function AppendText As StreamWriter

Creates a StreamWriter that appends text to the file represented by this instance of the FileInfo.

创建一个StreamWriter,将文本附加到由FileInfo的实例表示的文件。

2

Public Function Create As FileStream

Creates a file.

创建文件。

3

Public Overrides Sub Delete

Deletes a file permanently.

永久删除文件。

4

Public Sub MoveTo (destFileName As String )

Moves a specified file to a new location, providing the option to specify a new file name.

将指定的文件移动到新位置,提供指定新文件名的选项。

5

Public Function Open (mode As FileMode) As FileStream

Opens a file in the specified mode.

以指定模式打开文件。

6

Public Function Open (mode As FileMode, access As FileAccess ) As FileStream

Opens a file in the specified mode with read, write, or read/write access.

以指定模式打开具有读取,写入或读/写访问权限的文件。

7

Public Function Open (mode As FileMode, access As FileAccess, share As FileShare ) As FileStream

Opens a file in the specified mode with read, write, or read/write access and the specified sharing option.

以指定模式打开具有读取,写入或读/写访问权限以及指定的共享选项的文件。

8

Public Function OpenRead As FileStream

Creates a read-only FileStream

创建只读FileStream

9

Public Function OpenWrite As FileStream

Creates a write-only FileStream.

创建只写FileStream。

有关属性和方法的完整列表,请访问Microsoft的文档

示例:

以下示例演示了上述类的使用:

Imports System.IO
Module fileProg
   Sub Main()
      'creating a DirectoryInfo object
      Dim mydir As DirectoryInfo = New DirectoryInfo("c:Windows")
      ' getting the files in the directory, their names and size
      Dim f As FileInfo() = mydir.GetFiles()
      Dim file As FileInfo
      For Each file In f
          Console.WriteLine("File Name: {0} Size: {1}  ", file.Name, file.Length)
      Next file
      Console.ReadKey()
   End Sub
End Module
当编译和运行程序时,它在Windows目录中显示文件名及其大小。


VB.Net  文件处理VB.Net 文件处理


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)