Home » Windows API

DeleteFile

說明:
DeleteFile 函式可刪除指定的檔案


引用函式庫:
Kernel32


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


函式原型:

Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" ( _
    ByVal lpFileName As String _
    ) As Long



參數型態及說明:
lpFileNameString 要刪除的檔案的名稱

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

.NET Framework API:
System.IO.File.Delete
System.IO.FileInfo.Delete


VB範例:

檢視原始碼 Visual Basic
1
2
3
4
5
6
7
8
9
'VB的宣告
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" ( _
	ByVal lpFileName As String _
	) As Long
 
Dim rtvl As Long
 
'刪除C:\Windows API.txt
rtvl = DeleteFile("C:\Windows API.txt")

RB範例:

檢視原始碼 REALBasic
1
2
3
4
5
6
7
8
9
'RB的宣告
Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" ( _
	lpFileName As CString _
	) As Boolean
 
Dim rtvl As Boolean
 
'刪除C:\Windows API.txt
rtvl = DeleteFile("C:\Windows API.txt")

VB.NET範例:

1
2
3
4
5
6
7
8
9
10
11
'VB.NET的宣告
<DllImport("kernel32.dll")> _
Shared Function DeleteFile( _
	ByVal lpFilename As String _
	) As Boolean
End Function
 
Dim rtvl As Boolean
 
'刪除C:\Windows API.txt
rtvl = DeleteFile("C:\Windows API.txt")

C#範例:

1
2
3
4
5
6
7
8
9
10
//C#的宣告
[DllImport("kernel32")]
public static extern bool DeleteFile(
	string lpFileName
	);
 
bool rtvl;
 
//刪除C:\Windows API.txt
rtvl = DeleteFile(@"C:\Windows API.txt");

發表迴響