Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. Directories and Links > Removing a File or Directory: remove()

Removing a File or Directory: remove()

The remove() library function removes a file or an empty directory.

#include <stdio.h>

int remove(const char *pathname);

Note

Returns 0 on success, or -1 on error

If pathname is a file, remove() calls unlink(); if pathname is a directory, remove() calls rmdir().

Like unlink() and rmdir(), remove() doesn’t dereference symbolic links. If pathname is a symbolic link, remove() removes the link itself, rather than the file to which it refers.

If we want to remove a file in preparation for creating a new file with the same name, then using remove() is simpler than code that checks whether a pathname refers to a file or directory and calls unlink() or rmdir().


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint