C/File/File Delete
Версия от 14:20, 25 мая 2010; (обсуждение)
Delete a file
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(void)
{
char fname[80];
printf("Enter name of file to delete: ");
gets(fname);
printf("Are you sure? (Y/N) ");
if(toupper(getchar())=="Y")
remove(fname);
return 0;
}
Delete a file: how to use remove
#include <stdio.h>
int main ()
{
if( remove( "m.txt" ) == -1 )
perror( "Error deleting m.txt" );
else
puts( "File deleted" );
return 0;
}
Delete file
#include <stdio.h>
int main(int argc, char *argv[])
{
if(remove(argv[1])) printf("Remove Error");
return 0;
}
Delete file 2
#include <stdio.h>
int main(int argc, char *argv[])
{
if(rename(argv[1], argv[2]) != 0) printf("Rename Error");
return 0;
}