파일 디렉토리
파일 작업을 할 때, 파일이 저장된 디렉토리를 참조해야 하는 순간이 있습니다. GameMaker는 필요한 다양한 디렉토리와 관련된 특별한 함수와 변수를 제공합니다. HTML5 및 GX.gamestargets에서는 디렉토리를 생성하거나 삭제할 수 없습니다.
함수 참조
함수 이름 | 설명 |
---|---|
directory_exists | 지정한 디렉토리가 존재하는지 확인합니다. |
directory_create | 새로운 디렉토리를 생성합니다. |
directory_destroy | 지정한 디렉토리를 삭제합니다. |
변수 참조
변수 이름 | 설명 |
---|---|
paths | 파일 경로와 관련된 정보를 포함합니다. |
temp_directory | 임시 파일을 저장하는 디렉토리입니다. |
working_directory | 현재 작업 중인 디렉토리입니다. |
program_directory | 프로그램이 실행되는 디렉토리입니다. |
cache_directory | 캐시 파일이 저장되는 디렉토리입니다. |
game_save_id | 게임 저장과 관련된 ID입니다. |
활용 예제
1. 디렉토리 존재 여부 확인하기
if (directory_exists("my_directory")) {
show_message("디렉토리가 존재합니다.");
} else {
show_message("디렉토리가 존재하지 않습니다.");
}
2. 새로운 디렉토리 생성하기
if (!directory_exists("new_directory")) {
directory_create("new_directory");
show_message("새로운 디렉토리를 생성했습니다.");
}
3. 디렉토리 삭제하기
if (directory_exists("old_directory")) {
directory_destroy("old_directory");
show_message("디렉토리를 삭제했습니다.");
}
4. 임시 디렉토리 사용하기
var temp_file_path = temp_directory + "/temp_file.txt";
file_text_open_write(temp_file_path);
file_text_write_string(temp_file_path, "임시 파일 내용");
file_text_close(temp_file_path);
5. 현재 작업 디렉토리 확인하기
var current_directory = working_directory;
show_message("현재 작업 디렉토리: " + current_directory);
이 문서에서는 GameMaker에서 파일 디렉토리와 관련된 기본적인 함수와 변수를 설명했습니다. 다양한 활용 예제를 통해 실제로 어떻게 사용할 수 있는지 보여주었습니다.