Name

remove - delete a name and possibly the file it refers to

Library

libc.lib

Synopsis

  #include <stdio.h>
  int remove (const char *path);

Return values

Upon successful completion, reomve return 0. Otherwise, -1 is returned and the global variable errno is set to indicate the error.


Detailed description

The remove function removes the file or directory specified by path.

If path specifies a directory, remove (path);
is the equivalent of rmdir (path);
Otherwise, it is the equivalent of unlink (path);


Examples

/****************** this program shows deleting a file using remove **************/
#include <stdio.h>
int main()
{
        char * name = "C:\\input.txt";
        FILE *fp = fopen(name, "w+");
        if (fp == NULL)
                {
                printf ("fopen failed\n");
                return -1;
                }
        fprintf(fp,"hello world");
        fclose(fp);
        
        remove(name);
        fp=fopen(name,"r");
        if (fp == NULL)
                {
                printf ("file has been deleted already\n");
                }
        else
                {
                printf("remove failed\n");
                return -1;
                }
        
        return 0;
}

         

Output

file has been deleted already

         

Errors

The remove function may fail and set errno for any of the errors specified for the routines lstat, rmdir or unlink.

See also

rmdir, unlink


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top