파일 이름 변경

int rename( const char *oldname, const char *newname )

rename : return이 0이면 정상, -1이면 오류

 

#include <stdio.h>

void reName(char *input, char *newName)
{	
	/* Attempt to rename file: */
	int result = rename(input, newName);
	if (result != 0)
		printf("Could not rename '%s'\n", input);
	else
		printf("File '%s' renamed to '%s'\n", input, newName);
}

int main() {
	char input[MAX_PATH];
	char newName[MAX_PATH];
    
	printf_s("input old_name : ");
	scanf_s("%s", &input, sizeof(input));
	printf_s("input new_name : ");
	scanf_s("%s", &newName, sizeof(newName)); 
    
	reName(input, newName);
}

참고 : https://docs.microsoft.com/ko-kr/cpp/c-runtime-library/reference/rename-wrename?view=vs-2019

 

 

다른 글

2019/09/11 - [언어/C, C++] - [C++, Windows] 파일 찾기, 폴더 내 파일 목록 출력하기

 

[C++, Windows] 파일 찾기, 폴더 내 파일 목록 출력하기

파일 찾기 특정 파일명을 입력받아 그 파일이 cpp 파일이 존재하는 현재 폴더에 있는지 확인하기 #include #include #include #include void findFirstFile(TCHAR *input) { WIN32_FIND_DATA FindFileData; HANDL..

hydroponicglass.tistory.com