字體:小 中 大 | |
|
|
2009/03/23 22:52:19瀏覽991|回應59|推薦0 | |
On last week we only talk a little about file system! so at this week we shall talk more detail about it! and also you will try to use its object to create an new directory ..etc work to let you know how the system.io is useful to program design! have fun with it! see all of you tomorrow morning!
homework coding 【程式碼】 FileName:DirectoryInfo-1.sln 01 Imports System.io 03 Module Module1 05 Sub Main() ‘ 建立DirectoryInfo類別的dir物件, 可用來操作資料夾目錄 06 Dim dir As New DirectoryInfo("C:\vb2005") 07 If dir.Exists Then ‘判斷目錄是否存在 08 Console.WriteLine("C:\vb2005路徑存在, 不建立目錄") 09 Else 10 Console.WriteLine("C:\vb2005路徑不存在,建立目錄") 11 dir.Create() ‘建立目錄 12 dir.Refresh() ‘重新整理目錄 13 End If 14 Console.WriteLine("{0}檔案資訊如下:", dir.FullName) 15 Console.WriteLine("建立時間:{0}", dir.CreationTime) 16 Console.WriteLine("存取時間:{0}", dir.LastAccessTime) 17 Console.WriteLine("資料夾名稱:{0}", dir.Name) 18 Console.WriteLine("根目錄:{0}", dir.Parent) 19 Console.WriteLine() 20 Console.Write("是否刪除C:\vb2005資料夾 1.刪除 2.不刪除->") 21 If Console.ReadLine = "1" Then 22 Try 23 dir.Delete() ‘刪除檔案 24 Console.WriteLine("刪除成功") 25 Catch ex As Exception ‘刪除檔案失敗會產生例外 26 Console.WriteLine("刪除失敗") 27 End Try 28 End If 29 Console.Read() 30 End Sub 31 32 End Module |
|
( 知識學習|其他 ) |