rename
提供: cppreference.com
ヘッダ <stdio.h> で定義
|
||
int rename( const char *old_filename, const char *new_filename ); |
||
ファイルのファイル名を変更します。 ファイルは old_filename
の指す文字列によって表されます。 新しいファイル名は new_filename
の指す文字列によって表されます。
new_filename
が存在する場合、動作は処理系定義です。
目次 |
[編集] 引数
old_filename | - | 名前変更するファイルを表すパスを格納しているヌル終端文字列を指すポインタ |
new_filename | - | ファイルの新しいパスを格納しているヌル終端文字列を指すポインタ |
[編集] 戻り値
成功した場合は 0、エラーが発生した場合は非ゼロの値。
[編集] ノート
POSIX はこの関数の意味論について多数の追加の詳細を規定しています。
[編集] 例
Run this code
#include <stdio.h> int main(void) { FILE* fp = fopen("from.txt", "w"); // create file "from.txt" if(!fp) { perror("from.txt"); return 1; } fputc('a', fp); // write to "from.txt" fclose(fp); int rc = rename("from.txt", "to.txt"); if(rc) { perror("rename"); return 1; } fp = fopen("to.txt", "r"); if(!fp) { perror("to.txt"); return 1; } printf("%c\n", fgetc(fp)); // read from "to.txt" fclose(fp); }
出力:
a