remove, _wremove

刪除檔案。

語法

int remove(
   const char *path
);
int _wremove(
   const wchar_t *path
);

參數

path
要移除之檔案的路徑。

傳回值

如果已成功刪除檔案,這些函式每個都會傳回 0。 否則,它會傳回 -1,並將 errno 設定為 EACCES ,表示路徑指定唯讀檔案、指定目錄或檔案已開啟,或 ENOENT 表示找不到檔案名或路徑。

如需傳回碼的詳細資訊,請參閱 errno_doserrno_sys_errlist_sys_nerr

備註

remove 式會刪除 所 _wremovepath 指定的檔案,是 的寬字元版本 _remove ; path 的引數 _wremove 為寬字元字串。 否則,_wremove_remove 的行為即會相同。 必須先關閉檔案的所有處理常式,才能刪除它。

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

泛型文字常式對應

TCHAR.H 常規 _UNICODE_MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tremove remove remove _wremove

需求

常式 必要的標頭
remove <stdio.h><io.h>
_wremove <stdio.h><wchar.h>

如需相容性詳細資訊,請參閱相容性

程式庫

所有版本的 C 執行階段程式庫

範例

// crt_remove.c
/* This program uses remove to delete crt_remove.txt */

#include <stdio.h>

int main( void )
{
   if( remove( "crt_remove.txt" ) == -1 )
      perror( "Could not delete 'CRT_REMOVE.TXT'" );
   else
      printf( "Deleted 'CRT_REMOVE.TXT'\n" );
}

輸入: crt_remove.txt

This file will be deleted.

範例輸出

Deleted 'CRT_REMOVE.TXT'

另請參閱

檔案處理
_unlink, _wunlink