說明:
RemoveDirectory 函式可刪除指定的資料夾
引用函式庫:
Kernel32
適用系統:
Windows NT 3.1 或 Windows 95以上
函式原型:
Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" ( _ ByVal lpPathName As String _ ) As Long
參數型態及說明:
lpPathName:String 要被刪除的資料夾名
回傳值:
Long 呼叫成功的話,將會回傳非零的數值;若呼叫失敗的話,則回傳 0
.NET Framework API:
System.IO.Directory.Delete
System.IO.DirectoryInfo.Delete
VB範例:
檢視原始碼 Visual Basic
1 2 3 4 5 6 7 8 9 | 'VB的宣告 Private Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" ( _ ByVal lpPathName As String _ ) As Long Dim rtvl As Long '刪除C:\VB\Windows API\資料夾 rtvl = RemoveDirectory("C:\VB\Windows API\") |
RB範例:
檢視原始碼 REALBasic
1 2 3 4 5 6 7 8 9 | 'RB的宣告 Declare Function RemoveDirectory Lib "kernel32" Alias "RemoveDirectoryA" ( _ lpPathName As CString _ ) As Boolean Dim rtvl As Boolean '刪除C:\RB\Windows API\資料夾 rtvl = RemoveDirectory("C:\RB\Windows API\") |
VB.NET範例:
檢視原始碼 VB.NET
1 2 3 4 5 6 7 8 9 10 11 | 'VB.NET的宣告 <DllImport("kernel32.dll")> _ Shared Function RemoveDirectory( _ ByVal lpPathName As String _ ) As Boolean End Function Dim rtvl As Boolean '刪除C:\VB.NET\Windows API\資料夾 rtvl = RemoveDirectory("C:\VB.NET\Windows API\") |
C#範例:
檢視原始碼 C#
1 2 3 4 5 6 7 8 9 10 | //C#的宣告 [DllImport("kernel32")] public static extern bool RemoveDirectory( string lpPathName ); bool rtvl; //刪除C:\C_Sharp\Windows API\資料夾 rtvl = RemoveDirectory(@"C:\C_Sharp\Windows API\"); |
註釋:
呼叫 RemoveDirectory 函式時,要刪除的資料夾中不能有檔案存在