使用CreateDirectory物件的My.Computer.FileSystem方法來建立目錄。
如果目錄已經存在,則不會丟出例外。
建立目錄
使用
CreateDirectory方法,指定應建立目錄位置的完整路徑。 此範例會在NewDirectory中建立 名為C:\Documents and Settings\All Users\Documents的目錄。My.Computer.FileSystem.CreateDirectory( "C:\Documents and Settings\All Users\Documents\NewDirectory")
健全的程式設計
以下條件可能會造成例外狀況:
目錄名稱的格式不正確。 例如,它包含不合法的字元,或只是空格符 (ArgumentException)。
要建立之目錄的父目錄是唯讀的 (IOException)。
目錄名稱為
Nothing(ArgumentNullException)。目錄名稱太長(PathTooLongException)。
目錄名稱是冒號 “:” (NotSupportedException)。
用戶沒有建立目錄的許可權(UnauthorizedAccessException)。
使用者在部分信任環境中缺乏許可權(SecurityException)。