remove


remove

Unlinks a file

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

The remove( ) function deletes the file (or directory) referred to by its string argument. To be exact, it "unlinks" the file, or deletes its filename from the file system, so that the file's contents may still exist if the file was linked to more than one name.

The remove( ) function may or may not be able to unlink a file while it is open, depending on the given implementation. The function returns 0 on success. If remove( ) fails to unlink the file, it returns a nonzero value.

Example

 char fname_tmp[L_tmpnam] = ""; FILE *fp; int result; tmpnam( fname_tmp ); fp = fopen( fname_tmp, "w+" ); /* ... write something in the file, edit it ... */ fclose( fp ); result = rename( fname_tmp, "finished.txt" ); if ( result )              // Delete previous "finished.txt" and try again. {   remove( "finished.txt" );   result = rename( fname_tmp, "finished.txt" );   if ( result )                   // Give up and log the error.     fprintf( stderr, "Error %d on trying to rename output file\n", errno ); } 

See Also

fopen( ), tmpfile( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net