Remove

From aldeid
Jump to navigation Jump to search

Syntax

int remove ( const char * filename );

Description

Remove file

Deletes the file whose name is specified in filename.

This is an operation performed directly on a file identified by its filename; No streams are involved in the operation.

Proper file access shall be available.

Parameters

filename
C string containing the name of the file to be deleted.
Its value shall follow the file name specifications of the running environment and can include a path (if supported by the system).

Return value

If the file is successfully deleted, a zero value is returned.

On failure, a nonzero value is returned.

On most library implementations, the errno variable is also set to a system-specific error code on failure.

Example

Source Run
#include <stdio.h>

int main(int argc, char *argv[])
{
  int res = 0;

  res = remove("info.dat");
  if (res == 0) puts("File successfully removed");
  else perror("Error removing file");

  return 0;
}
$ ./code
File successfully removed
$ ./code
Error removing file: No such file or directory