以下是DirectoryInfo類的一些常用屬性:
S.N | 屬性名稱和說明 |
---|---|
1 | Attributes Gets the attributes for the current file or directory. 獲取當(dāng)前文件或目錄的屬性。 |
2 | CreationTime Gets the creation time of the current file or directory. 獲取當(dāng)前文件或目錄的創(chuàng)建時間。 |
3 | Exists Gets a Boolean value indicating whether the directory exists. 獲取指示該目錄是否存在的布爾值。 |
4 | Extension Gets the string representing the file extension. 獲取表示文件擴(kuò)展名的字符串。 |
5 | FullName Gets the full path of the directory or file. 獲取目錄或文件的完整路徑。 |
6 | LastAccessTime Gets the time the current file or directory was last accessed. 獲取上次訪問當(dāng)前文件或目錄的時間。 |
7 | Name Gets the name of this DirectoryInfo instance. 獲取此DirectoryInfo實(shí)例的名稱。 |
以下是DirectoryInfo類的一些常用方法:
S.N | 方法名稱和用途 |
---|---|
1 | Public Sub Create Creates a directory. 創(chuàng)建目錄。 |
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. 在指定的路徑上創(chuàng)建子目錄或子目錄。 指定的路徑可以相對于DirectoryInfo類的此實(shí)例。 |
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. 返回當(dāng)前目錄的子目錄。 |
5 | Public Function GetFiles As FileInfo() Returns a file list from the current directory. 從當(dāng)前目錄返回文件列表。 |
S.N | 屬性名稱和說明 |
---|---|
1 | Attributes Gets the attributes for the current file. 獲取當(dāng)前文件的屬性。 |
2 | CreationTime Gets the creation time of the current file. 獲取當(dāng)前文件的創(chuàng)建時間。 |
3 | Directory Gets an instance of the directory, which the file belongs to. 獲取該文件所屬的目錄的實(shí)例。 |
4 | Exists Gets a Boolean value indicating whether the file exists. 獲取指示文件是否存在的布爾值。 |
5 | Extension Gets the string representing the file extension. 獲取表示文件擴(kuò)展名的字符串。 |
6 | FullName Gets the full path of the file. 獲取文件的完整路徑。 |
7 | LastAccessTime Gets the time the current file was last accessed. 獲取當(dāng)前文件上次訪問的時間。 |
8 | LastWriteTime Gets the time of the last written activity of the file. 獲取文件的上次寫入活動的時間。 |
9 | Length Gets the size, in bytes, of the current file. 獲取當(dāng)前文件的大?。ㄒ宰止?jié)為單位)。 |
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. 創(chuàng)建一個StreamWriter,將文本附加到由FileInfo的實(shí)例表示的文件。 |
2 | Public Function Create As FileStream Creates a file. 創(chuàng)建文件。 |
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. 以指定模式打開具有讀取,寫入或讀/寫訪問權(quán)限的文件。 |
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. 以指定模式打開具有讀取,寫入或讀/寫訪問權(quán)限以及指定的共享選項的文件。 |
8 | Public Function OpenRead As FileStream Creates a read-only FileStream 創(chuàng)建只讀FileStream |
9 | Public Function OpenWrite As FileStream Creates a write-only FileStream. 創(chuàng)建只寫FileStream。 |
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
當(dāng)編譯和運(yùn)行程序時,它在Windows目錄中顯示文件名及其大小。
更多建議: