?
This document uses PHP Chinese website manual Release
在頭文件<stdio.h>中定義 | ||
---|---|---|
int remove(const char * fname); |
Deletes the file identified by character string pointed to by fname
.
如果該文件當(dāng)前由該進(jìn)程或其他進(jìn)程打開,則此函數(shù)的行為是由實(shí)現(xiàn)定義的(特別是,POSIX系統(tǒng)取消鏈接文件名,盡管在上次運(yùn)行進(jìn)程關(guān)閉文件之前文件系統(tǒng)空間不會被回收; Windows會不允許刪除文件)。
FNAME | - | 指向包含標(biāo)識要刪除的文件的路徑的以空字符結(jié)尾的字符串 |
---|
0
一旦成功或錯(cuò)誤發(fā)生非零值。
POSIX為這個(gè)函數(shù)的行為指定了許多額外的細(xì)節(jié)。
#include <stdio.h>int main(void){ FILE* fp = fopen("file1.txt", "w"); // create file if(!fp) { perror("file1.txt"); return 1; } puts("Created file1.txt"); fclose(fp); int rc = remove("file1.txt"); if(rc) { perror("remove"); return 1; } puts("Removed file1.txt"); fp = fopen("file1.txt", "r"); // Failure: file does not exist if(!fp) perror("Opening removed file failed"); rc = remove("file1.txt"); // Failure: file does not exist if(rc) perror("Double-remove failed");}
輸出:
Created file1.txt Removed file1.txt Opening removed file failed: No such file or directory Double-remove failed: No such file or directory
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.21.4.1刪除功能(p:302)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.19.4.1刪除功能(p:268)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.9.4.1刪除功能