Delete a file.
int _unlink( const char *filename );
int _wunlink( const wchar_t *filename );
Routine | Required Header | Compatibility |
_unlink | <io.h> and <stdio.h> | Win 95, Win NT |
_wunlink | <io.h> or <wchar.h> | Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
Each of these functions returns 0 if successful. Otherwise, the function returns –1 and sets errno to EACCES, which means the path specifies a read-only file, or to ENOENT, which means the file or path is not found or the path specified a directory.
Parameter
filename
Name of file to remove
Remarks
The _unlink function deletes the file specified by filename. _wunlink is a wide-character version of _unlink; the filename argument to _wunlink is a wide-character string. These functions behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine | _UNICODE & _MBCS Not Defined | _MBCS Defined | _UNICODE Defined |
_tunlink | _unlink | _unlink | _wunlink |
Example
/* UNLINK.C: This program uses _unlink to delete UNLINK.OBJ. */
#include <stdio.h>
void main( void )
{
if( _unlink( "unlink.obj" ) == -1 )
perror( "Could not delete 'UNLINK.OBJ'" );
else
printf( "Deleted 'UNLINK.OBJ'\n" );
}
Output
Deleted 'UNLINK.OBJ'