C 獲得當前路徑(目錄)的方法

2021-07-05 14:08:42 字數 1137 閱讀 1935

c# 獲得當前路徑(目錄)的方法

assembly myassembly = assembly.getentryassembly();

string path = myassembly.location;

directoryinfo dr = new directoryinfo(path);

path=dr.parent; //當前目錄的上一級目錄

system.environment.currentdirectory;

//例: c:\test

//例: c:\test

c#獲取程式當前路徑的方法

//獲取新的 process 元件並將其與當前活動的程序關聯的主模組的完整路徑,包含檔名(程序名)。

string str = system.diagnostics.process.getcurrentprocess().mainmodule.filename;

result: x:\***\***\***.exe (.exe檔案所在的目錄+.exe檔名)

//獲取和設定當前目錄(即該程序從中啟動的目錄)的完全限定路徑。

string str = system.environment.currentdirectory;

result: x:\***\*** (.exe檔案所在的目錄)

//獲取當前 thread 的當前應用程式域的基目錄,它由程式集衝突解決程式用來探測程式集。

result: x:\***\***\ (.exe檔案所在的目錄+"\")

//獲取和設定包含該應用程式的目錄的名稱。

result: x:\***\***\ (.exe檔案所在的目錄+"\")

//獲取啟動了應用程式的可執行檔案的路徑,不包括可執行檔案的名稱。

result: x:\***\*** (.exe檔案所在的目錄)

//獲取啟動了應用程式的可執行檔案的路徑,包括可執行檔案的名稱。

result: x:\***\***\***.exe (.exe檔案所在的目錄+.exe檔名)

//獲取應用程式的當前工作目錄(不可靠)。

string str = system.io.directory.getcurrentdirectory();

result: x:\***\*** (.exe檔案所在的目錄)

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...

VC 中獲得當前路徑的方法

1 以下 來自csdn 2004 vc程式設計經驗總結 cstring strpath getcurrentdirectory max path,strpath.getbuffer max path strpath.releasebuffer return strpath 2 以下 來自tz mfc...