快捷登錄,享 免費下載
首頁 > 軟件列表 > deletefile
deletefile

deletefile

軟件語言:簡體中文
軟件授權:免費軟件
適用系統(tǒng):Windows
創(chuàng)建時間:2021-01-12
軟件廠商/開發(fā)者信息:獨立開發(fā)者

介紹(MFC)

用法

DeleteFile 方法刪除指定文件。

object.DeleteFile ( filespec[, force] );

參數(shù)

object

必選項。 應為 FileSystemObject 的名稱。

filespec

必選項。 要刪除的文件的名稱。filespec可以在最后的路徑成分中包含通配字符。

force

可選項。 Boolean 值,如果要刪除設置了只讀屬性的文件,則為true;如果不刪除則為false(默認)。

介紹(VC)

刪除一個存在的文件。

用法

DeleteFile 方法刪除指定文件。

BOOL DeleteFile(

LPCSTRlpFileName//要刪除的文件名的指針

);

參數(shù)

lpFileName

必選項。要刪除文件的路徑。

返回值

成功返回非零,失敗返回0

更多錯誤信息使用GetLastError獲取。

如果程序嘗試刪除一個不存在的文件。GetLastError返回ERROR_FILE_NOT_FOUND。如果文件是只讀 的,則GetLastError返回ERROR_ACCESS_DENIED

注:

在2000/NT/XP系統(tǒng)下,如果程序試圖去刪除一個輸入輸出文件或者是內存映射文件函數(shù)調用就會失敗

說明

如果找不到匹配的文件則出錯。DeleteFile方法在遇到第一個錯誤時終止。 出錯后不試圖回滾或撤消出錯前做的修改。

MFC示例

CString type,dPath;

dPath.Format("%s\\Log\\",SystemDir); //指定路徑

BOOL ret=0;

CFileFind tempFind;

CString foundFileName,tempFileName;

CString tempFileFind=dPath+_T("*.*");

BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);

while(IsFinded)

{

IsFinded=(BOOL)tempFind.FindNextFile();

if(!tempFind.IsDots())

{

foundFileName=tempFind.GetFileName();

tempFileName=dPath+foundFileName;

ret = DeleteFile(tempFileName); // 刪除文件

}

}

tempFind.Close();

VC示例

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

{

TCHAR ch;

BOOL b = DeleteFile("D:\\1.txt");

if(!b)

{

DWORD d = GetLastError();

sprintf(ch,"刪除失??!錯誤代碼:%d",d);

MessageBox(NULL,ch,"刪除文件失??!",MB_OK | MB_ICONERROR);

return 0;

}

MessageBox(NULL,"刪除文件成功","刪除文件成功!",MB_OK);

return 0;

}

在C#中使用

導入庫:kernel32.dll

***.Net中運用

命名空間 using System.Runtime.InteropServices;

導入庫  [DllImport("kernel32.dll", EntryPoint = "DeleteFile")]

函數(shù)原型 public static extern bool DeleteFile(StringBuilder path);

參數(shù)說明 StringBuilder path,path指的是所要刪除文件的絕對路徑

返回值  布爾值

版本列表