Home » Windows API

MakeSureDirectoryPathExists

說明:
MakeSureDirectoryPathExists 函式可檢查所有指定的目錄是否存在,若不存在則建立


引用函式庫:
imagehlp


適用系統:
Windows NT 3.1 或 Windows 95以上


函式原型:

Declare Function MakeSureDirectoryPathExists Lib "imagehlp" ( _
    ByVal lpPath As String _
    ) As Long



參數型態及說明:
lpPathString 要檢查的路徑,必須以「\」做為結尾

回傳值:
Long 呼叫成功的話,將會回傳非零的數值;若呼叫失敗的話,則回傳 0

.NET Framework API:
System.IO.Directory.CreateDirectory


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
9
'VB的宣告
Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp" ( _
	ByVal lpPath As String _
	) As Long
 
Dim rtvl As Long
 
'檢查C:\VB\Windows API\是否存在,若不存在則建立
rtvl = MakeSureDirectoryPathExists("C:\VB\Windows API\")

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
9
'RB的宣告
Declare Function MakeSureDirectoryPathExists Lib "imagehlp" ( _
	lpPath As CString _
	) As Boolean
 
Dim rtvl As Boolean
 
'檢查C:\RB\Windows API\是否存在,若不存在則建立
rtvl = MakeSureDirectoryPathExists("C:\RB\Windows API\")

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
11
'VB.NET的宣告
<DllImport("imagehlp.dll")> _
Shared Function MakeSureDirectoryPathExists( _
	ByVal lpPath As String _
	) As Boolean
End Function
 
Dim rtvl As Boolean
 
'檢查C:\VB.NET\Windows API\是否存在,若不存在則建立
rtvl = MakeSureDirectoryPathExists("C:\VB.NET\Windows API\")

C#範例:

1
2
3
4
5
6
7
8
9
10
//C#的宣告
[DllImport("imagehlp")]
public static extern bool MakeSureDirectoryPathExists(
	string lpPath
	);
 
bool rtvl;
 
//檢查C:\C_Sharp\Windows API\是否存在,若不存在則建立
rtvl = MakeSureDirectoryPathExists(@"C:\C_Sharp\Windows API\");

發表迴響