RemoveFile Function

File Management

The RemoveFile function deletes an existing file.

BOOL RemoveFile( LPCWSTR lpFileName );

Parameters

  • lpFileName [in]
    Pointer to a null-terminated string that specifies the name of the file to be deleted. This parameter can be a fully qualified path or a relative path. The string must use the Windows character set.

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

  • If the specified file is read-only, RemoveFile will fail and return FALSE.
  • If the specified file is in use by another process, RemoveFile will fail and return FALSE.
  • You can use RemoveFile to delete a file from any directory for which you have delete access.
  • If the specified path is a directory, RemoveFile will fail and return FALSE.
  • To delete a directory, use the RemoveDirectory function.
  • When creating a file, you can specify the FILE_ATTRIBUTE_TEMPORARY attribute. This attribute can improve performance by indicating that the file is to be used for temporary storage. The system can move the file from main memory to the paging file as needed. If the file is not written to for a specified interval, the system can automatically delete it.

Requirements

Value
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header fileapi.h (include windows.h)
Library Kernel32.lib
DLL Kernel32.dll
Unicode and ANSI versions RemoveFileW (Unicode) and RemoveFileA (ANSI)

See Also

File Management Functions
RemoveDirectory