DeleteFileA function
Header: fileapi.h
Link library: Kernel32.lib
DLL: Kernel32.dll
Syntax
BOOL DeleteFileA(
LPCSTR lpFileName
);
Parameters
Parameter | Description |
---|---|
lpFileName |
A null-terminated string that specifies the name of the file to be deleted. You can use either a full path or a relative path. This parameter can be a string of any valid file name characters. |
Return value
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError
.
Remarks
This function marks a file for deletion. The file is deleted only when it is the last reference to it in the system.
To delete a directory, use the RemoveDirectory
function.
To delete a file that is read-only, you must first remove the read-only attribute. You can do this using the SetFileAttributes
function.
You can delete a file by specifying its name. You can also delete a file by specifying its file handle using the SetHandleInformation
function with HANDLE_FLAG_DELETE_ON_CLOSE
.
Requirements
Version | Minimum supported client | Minimum supported server |
---|---|---|
Windows XP | Windows XP | Windows Server 2003 |
Windows Vista | Windows Vista | Windows Server 2008 |
Windows 7 | Windows 7 | Windows Server 2008 R2 |
Windows 8 | Windows 8 | Windows Server 2012 |
Windows 8.1 | Windows 8.1 | Windows Server 2012 R2 |
Windows 10 | Windows 10 | Windows Server 2016 |
Windows 11 | Windows 11 | Windows Server 2022 |