RAD Studio |  |

_unlink, _wunlink

Header File

dos.h

Category

Input/output Routines

Prototype

int _unlink(const char *filename);

int _wunlink(const wchar_t *filename);

Description

Deletes a file.

_unlink deletes a file specified by filename. Any drive, path, and file name can be used as a filename. Wildcards are not allowed.

Read-only files cannot be deleted by this call. To remove read-only files, first use chmod or _rtl_chmod to change the read-only attribute.

Note: If the file is open, it must be closed before unlinking it.
_wunlink is the Unicode version of _wunlink. The Unicode version accepts a filename that is a wchar_t character string. Otherwise, the functions perform identically.

Return Value

On success, _unlink returns 0.

On error, it returns -1 and sets the global variable errno to one of the following values:

EACCES | Permission denied
ENOENT | Path or file name not found

Example

Copy Code

    #include <stdio.h>
    #include <io.h>
    int main(void)
    {
       FILE *fp = fopen("junk.jnk","w");
       int status;
       fprintf(fp,"junk");
       status = access("junk.jnk",0);
       if (status == 0)
          printf("File exists\n");
       else
          printf("File doesn't exist\n");
       fclose(fp);
       unlink("junk.jnk");
       status = access("junk.jnk",0);
       if (status == 0)
          printf("File exists\n");
       else
          printf("File doesn't exist\n");
       return 0;
    }

Portability

| POSIX | Win32 | ANSI C | ANSI C++
_unlink | + | + |  |
_wunlink |  | NT only |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!