Programing - C/C Basic grammar
119 파일 이름 변경( rename )
junmoyo
2017. 12. 27. 05:50
개념 :
1. stdio.h 에 포함되어 있다.
2. 원형 : int rename(const char *oldname, const char *newname);
3. path와 이름을 같이 사용 해야합니다.
4. 0을 리턴할 경우 정상적으로 이름이 변경된 것입니다.
소스코드 : main.c
#include<stdio.h>
#include<io.h>
int main(void)
{
FILE *fp = NULL;
char *oldName = "C:\\Users\\junmo\\Desktop\\300\\119\\file.txt";
char *newName = "C:\\Users\\junmo\\Desktop\\300\\119\\test.txt";
fopen_s(&fp, oldName, "w+");
if (fp == NULL)
{
perror("C:\\Users\\junmo\\Desktop\\300\\119\\file.txt");
}
else
{
fclose(fp);
if (rename(oldName, newName))
{
perror("C:\\Users\\junmo\\Desktop\\300\\119\\file.txt");
}
else
{
if (_access(newName, 0))
{
puts("test.txt 파일이 존재 하지 않습니다.");
}
else
{
puts("test.txt 파일이 존재 합니다");
}
}
}
system("pause");
return 0;
}
결과 :