Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

_unlink, _wunlink

Delete a file.

int _unlink(
   const char *filename 
);
int _wunlink(
   const wchar_t *filename 
);

Parameter

filename
Name of file to remove.

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.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, return codes.

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

Requirements

Routine Required header Compatibility
_unlink <io.h> and <stdio.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wunlink <io.h> or <wchar.h> Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

This program uses _unlink to delete CRT_UNLINK.TXT.

// crt_unlink.c

#include <stdio.h>

int main( void )
{
   if( _unlink( "crt_unlink.txt" ) == -1 )
      perror( "Could not delete 'CRT_UNLINK.TXT'" );
   else
      printf( "Deleted 'CRT_UNLINK.TXT'\n" );
}

Input: crt_unlink.txt

This file will be deleted.

Output

Deleted 'CRT_UNLINK.TXT'

See Also

File Handling Routines | _close | remove | Run-Time Routines and .NET Framework Equivalents

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.