一般寫程式時會了將來除錯容易 通常會讓程式在執行過程中產生.log 檔案 若不想要讓end user看到這些檔案 我們可以將log產生在%localappdate%這個隱藏資料夾裡面 For example 實際路徑可能長這樣: // C:\Users\User name\AppData\Local\MyProgram\DOTNETFX.log Sample code 如下: CString dnetTagFilePath=getCurrentUserDirectory()+_T("\\DOTNETFX.log"); // C:\Users\User name\AppData\Local\MyProgram\DOTNETFX.log 定義getCurrentUserDirectory 並更改_stprintf (path, _T("%s\\ MyProgram "), path); CString CAppTools::getCurrentUserDirectory() { CString szCurrentUserDirPath; TCHAR path[MAX_PATH]; memset (path, 0, MAX_PATH*sizeof(TCHAR)); SHGetFolderPath (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); _stprintf (path, _T(" %s\\MyProgram "), path); ::CreateDirectoryW (path, NULL); szCurrentUserDirPath.Format(_T("%s"), path); return szCurrentUserDirPath; }