VC 中獲得當前路徑的方法

2021-04-29 15:31:49 字數 681 閱讀 9889

1.//以下**來自csdn 2004 vc程式設計經驗總結

cstring strpath;

getcurrentdirectory(max_path,strpath.getbuffer(max_path));

strpath.releasebuffer();

return strpath;

}2.//以下**來自tz mfc.net primer 1.01

vc 獲得當前應用程式所在路徑(exe檔案的路徑)

vc 獲得當前應用程式所在路徑(exe檔案的路徑)

tchar szfilepath[max_path + 1];

getmodulefilename(null, szfilepath, max_path);

(_tcsrchr(szfilepath, _t('//')))[1] = 0; //刪除檔名,只獲得路徑

cstring str_url = szfilepath;

afxmessagebox(str_url);

使用第一段**可以獲得應用程式執行時所在目錄。但由於在使用microsoft visual studio.net編譯並執行專案時,真正的宿主是ide,所以當前目錄是專案所在目錄,並不是debug或者release目錄,這一點需要開發人員注意。而第二段**可以動態解決此問題。並且增加了unicode支援(tchar)。

Perl 獲得當前路徑

perl 獲得當前路徑 1 有兩種方法 1.use cwd my dir getcwd dir中即為當前目錄的完整路徑資訊。2.my dir env env是乙個雜湊,用於存放環境變數。pwd是linux的環境變數,表示當前所在目錄。my path pwd print path,n 2 staf的l...

python 獲得當前路徑

先要裝載 os模組 import os print os.getcwd 或者print os.path.abspath os.curdir print os.path.abspath 就可以了。代表當前的路徑,代表當前路徑的上一級路徑。這在unix和windows系統意義是類似的。例如 以winod...

在Python 中獲得當前路徑

先要裝載 os模組 import os print os.getcwd 或者 print os.path.abspath os.curdir print os.path.abspath 代表當前的路徑,代表當前路徑的上一級路徑。這在unix和windows系統意義是類似的。例如 以winodws系統...