file_bin_position 함수 설명
file_bin_position
함수는 주어진 파일 ID에 대한 현재 위치를 바이트 단위로 반환합니다. 여기서 0은 파일의 첫 번째 위치를 의미합니다. 파일 ID 값은 file_bin_open()
함수에 의해 반환됩니다.
주의: 이 함수들은 HTML5 모듈에서는 작동하지 않습니다.
문법
file_bin_position(binfile);
인수
인수 이름 | 타입 | 설명 |
---|---|---|
binfile | 정수 | 위치를 가져올 파일의 ID입니다. |
반환값
- 현재 파일의 위치를 바이트 단위로 반환합니다.
예제
pos = file_bin_position(file);
위 코드는 현재 위치를 변수 "pos"에 저장합니다.
활용 예제
- 파일 읽기 위치 확인하기
gml file = file_bin_open("example.bin", fm_read); pos = file_bin_position(file); show_message("현재 파일 위치: " + string(pos));
- 파일의 끝까지 이동 후 위치 확인하기
gml file = file_bin_open("example.bin", fm_read); file_bin_seek(file, 0, seek_end); pos = file_bin_position(file); show_message("파일 끝 위치: " + string(pos));
- 파일의 특정 위치로 이동 후 위치 확인하기
gml file = file_bin_open("example.bin", fm_read); file_bin_seek(file, 10, seek_start); pos = file_bin_position(file); show_message("10바이트 위치: " + string(pos));
- 파일을 읽고 현재 위치 출력하기
gml file = file_bin_open("example.bin", fm_read); data = file_bin_read(file, 4); pos = file_bin_position(file); show_message("읽은 데이터: " + string(data) + ", 현재 위치: " + string(pos));
- 파일을 열고 위치를 반복적으로 확인하기
gml file = file_bin_open("example.bin", fm_read); while (!file_bin_eof(file)) { data = file_bin_read(file, 1); pos = file_bin_position(file); show_message("읽은 데이터: " + string(data) + ", 현재 위치: " + string(pos)); }
이 예제들은 file_bin_position
함수를 활용하여 파일의 현재 위치를 확인하고, 다양한 파일 작업을 수행하는 방법을 보여줍니다.