Directory class
https://docs.microsoft.com/zh-cn/dotnet/api/system.io.directory?view=netframework-4.8
method
CreateDirectory(String) | Create all directories and subdirectories in the specified path unless they already exist. |
CreateDirectory(String, DirectorySecurity) | Create all directories in the specified path (unless already exists) and apply the specified Windows security. |
Delete(String) | Delete empty directories from the specified path. |
Delete(String, Boolean) | Delete the specified directory, and delete all subdirectories and files in the directory (if indicated). |
EnumerateDirectories(String) | Returns an enumerable collection of the complete names of the directories in the specified path. |
EnumerateDirectories(String, String) | Returns an enumerable collection of the full names of directories in the specified path that match the search pattern. |
EnumerateDirectories(String, String, SearchOption) | Returns an enumerable collection of full names of directories in the specified path that match the search pattern, and can also search subdirectories. |
EnumerateFiles(String) | Returns an enumerable collection of full file names in the specified path. |
EnumerateFiles(String, String) | Returns an enumerable collection of full file names matching the search pattern in the specified path. |
EnumerateFiles(String, String, SearchOption) | Returns an enumerable collection of complete file names that match the search pattern in the specified path, and can also search subdirectories. |
EnumerateFileSystemEntries(String) | Returns an enumerable collection of file names and directory names in the specified path. |
EnumerateFileSystemEntries(String, String) | Returns an enumerable collection of file names and directory names that match the search pattern in the specified path. |
EnumerateFileSystemEntries(String, String, SearchOption) | Returns an enumerable collection of file names and directory names that match the search pattern in the specified path, and can also search subdirectories. |
Exists(String) | Determines whether the given path refers to an existing directory on the disk. |
GetAccessControl(String) | Get the DirectorySecurity object, which encapsulates the access control list (ACL) items of the specified directory. |
GetAccessControl(String, AccessControlSections) | Get a DirectorySecurity object that encapsulates the specified type of access control list (ACL) entry for the specified directory. |
GetCreationTime(String) | Get the creation date and time of the directory. |
GetCreationTimeUtc(String) | Get the date and time when the catalog was created, the format is Coordinated Universal Time (UTC). |
GetCurrentDirectory() | Get the current working directory of the application. |
GetDirectories(String) | Returns the name (including the path) of subdirectories in the specified directory. |
GetDirectories(String, String) | Returns the name of the subdirectory in the specified directory that matches the specified search pattern (including its path). |
GetDirectories(String, String, SearchOption) | Returns the name of the subdirectory (including its path) that matches the specified search pattern in the specified directory, and optionally searches the subdirectory. |
GetDirectoryRoot(String) | Returns the volume information, root information, or both of the specified path. |
GetFiles(String) | Returns the name of the file in the specified directory (including its path). |
GetFiles(String, String) | Returns the name of the file in the specified directory that matches the specified search pattern (including its path). |
GetFiles(String, String, SearchOption) | Returns the name of the file in the specified directory that matches the specified search pattern (including its path), using a value to determine whether to search for subdirectories. |
GetFileSystemEntries(String) | Returns the names of all files and subdirectories in the specified path. |
GetFileSystemEntries(String, String) | Returns an array containing file names and directory names that match the search pattern in the specified path. |
GetFileSystemEntries(String, String, SearchOption) | Returns an array of all file names and directory names in the specified path that match the search pattern. You can also search for subdirectories. |
GetLastAccessTime(String) | Returns the date and time of the last access to the specified file or directory. |
GetLastAccessTimeUtc(String) | Returns the date and time of the last access to the specified file or directory, the format is Coordinated Universal Time (UTC). |
GetLastWriteTime(String) | Returns the date and time of the last write to the specified file or directory. |
GetLastWriteTimeUtc(String) | Returns the date and time of the last writing to the specified file or directory, the format is Coordinated Universal Time (UTC). |
GetLogicalDrives() | Retrieve the name of the logical drive on this computer in the format "<drive letter>: \". |
GetParent(String) | Retrieve the parent directory of the specified path, including absolute and relative paths. |
Move(String, String) | Move the file or directory and its contents to a new location. |
SetAccessControl (String, DirectorySecurity) | Apply the access control list (ACL) entry described by the DirectorySecurity object to the specified directory. |
SetCreationTime(String, DateTime) | Set the creation date and time for the specified file or directory. |
SetCreationTimeUtc(String, DateTime) | 设置指定文件或目录的创建日期和时间,其格式为协调通用时 (UTC)。 |
SetCurrentDirectory(String) | 将应用程序的当前工作目录设置为指定的目录。 |
SetLastAccessTime(String, DateTime) | 设置上次访问指定文件或目录的日期和时间。 |
SetLastAccessTimeUtc(String, DateTime) | 设置上次访问指定文件或目录的日期和时间,其格式为协调通用时 (UTC)。 |
SetLastWriteTime(String, DateTime) | 设置上次写入目录的日期和时间。 |
SetLastWriteTimeUtc(String, DateTime) | 设置上次写入某个目录的日期和时间,其格式为协调通用时 (UTC)。 |
文件夹操作主要包括创建、删除、移动以及检查目录是否存在。这4种操作分别对应于Directory类的下列方法:CreateDirectory,创建指定的目录,这个方法需要一个参数,即指明所创建的目录的路径名;Delete,删除指定的目录,这个方法也需要用一个参数来说明删除的文件夹名;Move,移动一个文件,这个方法需要两个参数,即被移动的源文件夹,以及移动后的目标日录;Exists,检查一个曰录是否存在,需要一个参数,指明所检奋的文件夹名。