FileSystem 类

定义

提供了用于处理驱动器、文件和目录的属性和方法。Provides properties and methods for working with drives, files, and directories.

public ref class FileSystem
public class FileSystem
type FileSystem = class
Public Class FileSystem
继承
FileSystem

示例

此示例将进行检查以确定文件夹 C:\backup\logs 是否存在并检查其属性。This example checks to determine whether the folder C:\backup\logs exists and checks its properties.

Dim logInfo As System.IO.DirectoryInfo
If My.Computer.FileSystem.DirectoryExists("C:\backup\logs") Then
    logInfo = My.Computer.FileSystem.GetDirectoryInfo(
      "C:\backup\logs")
End If

注解

下表列出了涉及 My.Computer.FileSystem 对象的任务示例。The following table lists examples of tasks involving the My.Computer.FileSystem object.

功能To 查看See
从文本文件读取Read from a text file 如何:读取文本文件How to: Read from Text Files
从带分隔符的文本文件中读取Read from a delimited text file 如何:读取逗号分隔的文本文件How to: Read From Comma-Delimited Text Files
从固定宽度文本文件中读取Read from a fixed-width text file 如何:读取固定宽度的文本文件How to: Read From Fixed-width Text Files
从具有多种格式的文本文件中读取Read from a text file with multiple formats 如何:读取具有多种格式的文本文件How to: Read From Text Files with Multiple Formats
从二进制文件读取Read from a binary file 如何:读取二进制文件How to: Read From Binary Files
使用 StreamReader 读取文本文件Read from a text file with a StreamReader 如何:使用 StreamReader 读取文件中的文本How to: Read Text from Files with a StreamReader
写入到文本文件Write to a text file 如何:向文件写入文本How to: Write Text to Files
追加到文本文件Append to a text file 如何:向文本文件追加内容How to: Append to Text Files
写入二进制文件Write to a binary file 如何:写入二进制文件How to: Write to Binary Files
写入MyDocuments目录中的文本文件Write to text files in the MyDocuments directory 如何:将文本写入“我的文档”目录中的文件How to: Write Text to Files in the My Documents Directory
使用 StreamWriter 写入文本文件Write to a text file with a StreamWriter 如何:使用 StreamWriter 向文件中写入文本How to: Write Text to Files with a StreamWriter
复制具有特定模式的文件Copy files with a specific pattern 如何:将具有特定模式的文件复制到目录中How to: Copy Files with a Specific Pattern to a Directory
将文件复制到相同的目录Copy a file to the same directory 如何:在同一目录中创建文件副本How to: Create a Copy of a File in the Same Directory
将文件复制到其他目录Copy a file to a different directory 如何:在不同的目录中创建文件的副本How to: Create a Copy of a File in a Different Directory
创建文件Create a file 如何:创建文件How to: Create a File
删除文件Delete a file 如何:删除文件How to: Delete a File
查找具有特定模式的文件Find files with a specific pattern 如何:查找具有特定模式的文件How to: Find Files with a Specific Pattern
移动文件Move a file 如何:移动文件How to: Move a File
重命名文件Rename a file 如何:重命名文件How to: Rename a File
将目录复制到另一个目录Copy a directory to another directory 如何:将一个目录复制到另一个目录How to: Copy a Directory to Another Directory
创建目录Create a directory 如何:创建目录How to: Create a Directory
查找具有特定模式的子目录Find subdirectories with a specific pattern 如何:查找具有特定模式的子目录How to: Find Subdirectories with a Specific Pattern
获取目录中的文件集合Get the collection of files in a directory 如何:获取目录中的文件集合How to: Get the Collection of Files in a Directory
MyDocuments目录中读取Read from the MyDocuments directory 如何:检索“我的文档”目录中的内容How to: Retrieve the Contents of the My Documents Directory
分析文件路径Parse a file path 如何:分析文件路径How to: Parse File Paths

构造函数

FileSystem()

初始化 FileSystem 类的新实例。Initializes a new instance of the FileSystem class.

属性

CurrentDirectory

获取或设置当前目录。Gets or sets the current directory.

Drives

返回所有可用驱动器名称的只读集合。Returns a read-only collection of all available drive names.

方法

CombinePath(String, String)

组合两个路径并返回一个格式正确的路径。Combines two paths and returns a properly formatted path.

CopyDirectory(String, String)

将目录内容复制到其他目录。Copies the contents of a directory to another directory.

CopyDirectory(String, String, Boolean)

将目录内容复制到其他目录。Copies the contents of a directory to another directory.

CopyDirectory(String, String, UIOption)

将目录内容复制到其他目录。Copies the contents of a directory to another directory.

CopyDirectory(String, String, UIOption, UICancelOption)

将目录内容复制到其他目录。Copies the contents of a directory to another directory.

CopyFile(String, String)

将文件复制到新的位置。Copies a file to a new location.

CopyFile(String, String, Boolean)

将文件复制到新的位置。Copies a file to a new location.

CopyFile(String, String, UIOption)

将文件复制到新的位置。Copies a file to a new location.

CopyFile(String, String, UIOption, UICancelOption)

将文件复制到新的位置。Copies a file to a new location.

CreateDirectory(String)

创建目录。Creates a directory.

DeleteDirectory(String, DeleteDirectoryOption)

删除目录。Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption)

删除目录。Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption, UICancelOption)

删除目录。Deletes a directory.

DeleteFile(String)

删除文件。Deletes a file.

DeleteFile(String, UIOption, RecycleOption)

删除文件。Deletes a file.

DeleteFile(String, UIOption, RecycleOption, UICancelOption)

删除文件。Deletes a file.

DirectoryExists(String)

如果指定目录存在,则返回 TrueReturns True if the specified directory exists.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FileExists(String)

如果指定文件存在,则返回 TrueReturns True if the specified file exists.

FindInFiles(String, String, Boolean, SearchOption)

返回字符串的只读集合,这些字符串表示包含指定文本的文件的名称。Returns a read-only collection of strings representing the names of files containing the specified text.

FindInFiles(String, String, Boolean, SearchOption, String[])

返回字符串的只读集合,这些字符串表示包含指定文本的文件的名称。Returns a read-only collection of strings representing the names of files containing the specified text.

GetDirectories(String)

返回一个字符串集合,这些字符串表示目录内子目录的路径名。Returns a collection of strings representing the path names of subdirectories within a directory.

GetDirectories(String, SearchOption, String[])

返回一个字符串集合,这些字符串表示目录内子目录的路径名。Returns a collection of strings representing the path names of subdirectories within a directory.

GetDirectoryInfo(String)

返回指定路径的 DirectoryInfo 对象。Returns a DirectoryInfo object for the specified path.

GetDriveInfo(String)

返回指定驱动器的 DriveInfo 对象。Returns a DriveInfo object for the specified drive.

GetFileInfo(String)

返回指定文件的 FileInfo 对象。Returns a FileInfo object for the specified file.

GetFiles(String)

返回字符串的只读集合,这些字符串表示目录内文件的名称。Returns a read-only collection of strings representing the names of files within a directory.

GetFiles(String, SearchOption, String[])

返回字符串的只读集合,这些字符串表示目录内文件的名称。Returns a read-only collection of strings representing the names of files within a directory.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetName(String)

从提供的路径分析文件名。Parses the file name out of the path provided.

GetParentPath(String)

返回所提供的路径的父路径。Returns the parent path of the provided path.

GetTempFileName()

在磁盘上创建一个唯一命名的零字节临时文件并返回该文件的完整路径。Creates a uniquely named zero-byte temporary file on disk and returns the full path of that file.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MoveDirectory(String, String)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, Boolean)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, UIOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, UIOption, UICancelOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveFile(String, String)

将文件移动到一个新位置。Moves a file to a new location.

MoveFile(String, String, Boolean)

将文件移动到一个新位置。Moves a file to a new location.

MoveFile(String, String, UIOption)

将文件移动到一个新位置。Moves a file to a new location.

MoveFile(String, String, UIOption, UICancelOption)

将文件移动到一个新位置。Moves a file to a new location.

OpenTextFieldParser(String)

使用 OpenTextFieldParser 方法可以创建 TextFieldParser 对象,该对象为分析结构化文本文件(例如日志)提供了一种简单而有效的方法。The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. TextFieldParser 对象可用于读取分隔文件和固定宽度文件。The TextFieldParser object can be used to read both delimited and fixed-width files.

OpenTextFieldParser(String, Int32[])

使用 OpenTextFieldParser 方法可以创建 TextFieldParser 对象,该对象为分析结构化文本文件(例如日志)提供了一种简单而有效的方法。The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. TextFieldParser 对象可用于读取分隔文件和固定宽度文件。The TextFieldParser object can be used to read both delimited and fixed-width files.

OpenTextFieldParser(String, String[])

使用 OpenTextFieldParser 方法可以创建 TextFieldParser 对象,该对象为分析结构化文本文件(例如日志)提供了一种简单而有效的方法。The OpenTextFieldParser method allows you to create a TextFieldParser object, which provides a way to easily and efficiently parse structured text files, such as logs. TextFieldParser 对象可用于读取分隔文件和固定宽度文件。The TextFieldParser object can be used to read both delimited and fixed-width files.

OpenTextFileReader(String)

打开要从文件中读取的 StreamReader 对象。Opens a StreamReader object to read from a file.

OpenTextFileReader(String, Encoding)

打开要从文件中读取的 StreamReader 对象。Opens a StreamReader object to read from a file.

OpenTextFileWriter(String, Boolean)

打开要写入指定文件的 StreamWriter 对象。Opens a StreamWriter object to write to the specified file.

OpenTextFileWriter(String, Boolean, Encoding)

打开要写入指定文件的 StreamWriterOpens a StreamWriter to write to the specified file.

ReadAllBytes(String)

以字节数组的形式返回文件的内容。Returns the contents of a file as a byte array.

ReadAllText(String)

将文本文件的内容作为 String 返回。Returns the contents of a text file as a String.

ReadAllText(String, Encoding)

将文本文件的内容作为 String 返回。Returns the contents of a text file as a String.

RenameDirectory(String, String)

重命名目录。Renames a directory.

RenameFile(String, String)

重命名文件。Renames a file.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
WriteAllBytes(String, Byte[], Boolean)

将数据写入二进制文件。Writes data to a binary file.

WriteAllText(String, String, Boolean)

向文件写入文本。Writes text to a file.

WriteAllText(String, String, Boolean, Encoding)

向文件写入文本。Writes text to a file.

适用于

另请参阅