티스토리 뷰

JavaScript 로 특정 디렉토리에 이미지 파일을 생성하고 해당 이미지 파일을 upload control 을 통해 서버측으로 전송해야할 일이 생겼다.

Windows 에서는 cmd /k set 명령어를 통해서 해당 PC의 환경변수값을 조회할 수 있다.
이 중에서 Windows 의 기본 환경변수 중 하나인 %TMP%, %TEMP% 디렉토리를 접근하고자 했는데. 직접 하드코딩을 하자니 문제가 발생할 수 있을 듯 해서 JavaScript 에서 환경변수를 읽어올 수 있는 방법을 찾아봤다.

결론은 못찾았다.. 뭐 있을 수도 있지만
시간도 부족하고, 귀찮기도 하고 (실은 이게 큰 이유..ㅡ.ㅡ;;)

일단 환경변수를 읽어오는 방법은 못찾았지만,
%TMP%나 %TEMP% 디렉토리를 접근할 수 있는 방법은 찾았다.

바로 FileSystemObject를 사용하면 된다.

var fso = new ActiveXObject("Scripting.FileSystemObject");
var temporaryDir = fso.GetSpecialFolder(2);

GetSpecialFoler 의 인수로는 0, 1, 2 세가지를 줄 수 있는데, 뜻은 다음과 같다.

Constant Value Description
WindowsFolder 0 The Windows folder contains files installed by the Windows operating system.
SystemFolder 1 The System folder contains libraries, fonts, and device drivers.
TemporaryFolder 2 The Temp folder is used to store temporary files. Its path is found in the TMP environment variable.

역시 모든 답은 메뉴얼에 있다.. ㅡ.ㅡ;;;
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함