C#的path.GetFullPath 獲取上級(jí)目錄實(shí)現(xiàn)方法
更新時(shí)間:2014年10月28日 10:15:30 投稿:shichen2014
這篇文章主要介紹了C#的path.GetFullPath 獲取上級(jí)目錄實(shí)現(xiàn)方法,包含了具體的C#實(shí)現(xiàn)方法以及ASP.net與ASP等的方法對(duì)比,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#的path.GetFullPath 獲取上級(jí)目錄實(shí)現(xiàn)方法,分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
string path = new directoryinfo("../").fullname;//當(dāng)前應(yīng)用程序路徑的上級(jí)目錄
獲取當(dāng)前目錄可以使用
復(fù)制代碼 代碼如下:
appdomain.currentdomain.basedirectory
獲取當(dāng)前目錄的上級(jí)目錄
復(fù)制代碼 代碼如下:
path.getfullpath("..")
具體代碼如下:
復(fù)制代碼 代碼如下:
using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.io;
namespace pathtest
{
class program
{
static void main(string[] args)
{
//使用appdomain獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄
string dir = appdomain.currentdomain.basedirectory;
string info = string.format("appdomain方法獲取當(dāng)前程序集目錄:{0}", dir);
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行的上級(jí)目錄
dir = path.getfullpath("..");
info = string.format("path方法獲取當(dāng)前程序集上級(jí)目錄:{0}", dir); (www.dhdzp.com)
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄的上級(jí)的上級(jí)目錄
dir = path.getfullpath(@"....");
info = string.format("path方法獲取當(dāng)前程序集目錄的級(jí)的上級(jí)目錄:{0}", dir);
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄的上級(jí)目錄
dir = path.getfullpath(@"......");
info = string.format("path方法獲取當(dāng)前程序集目錄的上級(jí)目錄的上級(jí)目錄:{0}", dir);
console.writeline(info);
//在當(dāng)前程序集目錄中添加指定目錄
dir = path.getfullpath(@"io");
info = string.format("在當(dāng)前程序集目錄中添加指定目錄:{0}", dir);
console.writeline(info);
console.read();
}
}
}
using system.collections.generic;
using system.linq;
using system.text;
using system.io;
namespace pathtest
{
class program
{
static void main(string[] args)
{
//使用appdomain獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄
string dir = appdomain.currentdomain.basedirectory;
string info = string.format("appdomain方法獲取當(dāng)前程序集目錄:{0}", dir);
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行的上級(jí)目錄
dir = path.getfullpath("..");
info = string.format("path方法獲取當(dāng)前程序集上級(jí)目錄:{0}", dir); (www.dhdzp.com)
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄的上級(jí)的上級(jí)目錄
dir = path.getfullpath(@"....");
info = string.format("path方法獲取當(dāng)前程序集目錄的級(jí)的上級(jí)目錄:{0}", dir);
console.writeline(info);
//使用path獲取當(dāng)前應(yīng)用程序集的執(zhí)行目錄的上級(jí)目錄
dir = path.getfullpath(@"......");
info = string.format("path方法獲取當(dāng)前程序集目錄的上級(jí)目錄的上級(jí)目錄:{0}", dir);
console.writeline(info);
//在當(dāng)前程序集目錄中添加指定目錄
dir = path.getfullpath(@"io");
info = string.format("在當(dāng)前程序集目錄中添加指定目錄:{0}", dir);
console.writeline(info);
console.read();
}
}
}
winform比較復(fù)雜,我只知道environment.currentdirectory是當(dāng)前exe的路徑,你要得到上一級(jí)的再用這個(gè)路徑算。
asp就比.net簡(jiǎn)單了,直接../就行了
如果是asp.net直接用server.mappath("~/bg/")就可以了。
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#通過(guò)正則表達(dá)式實(shí)現(xiàn)提取網(wǎng)頁(yè)中的圖片
本文給大家分享的是使用C#通過(guò)正則表達(dá)式來(lái)實(shí)現(xiàn)提取網(wǎng)頁(yè)中的圖片的代碼,十分的方便,有需要的小伙伴可以參考下。2015-12-12
Windows窗體的.Net框架繪圖技術(shù)實(shí)現(xiàn)方法
這篇文章主要介紹了Windows窗體的.Net框架繪圖技術(shù)實(shí)現(xiàn)方法,非常實(shí)用,需要的朋友可以參考下2014-08-08
C#實(shí)現(xiàn)套接字發(fā)送接收數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)套接字發(fā)送接收數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11
使用C#實(shí)現(xiàn)讀取系統(tǒng)配置文件的代碼實(shí)例講解
這篇文章主要介紹了使用C#實(shí)現(xiàn)讀取系統(tǒng)配置文件的代碼實(shí)例,使用到了ConfigurationManager類,需要的朋友可以參考下2015-12-12
UnityShader3實(shí)現(xiàn)轉(zhuǎn)圈與冷卻效果
這篇文章主要為大家詳細(xì)介紹了UnityShader3實(shí)現(xiàn)轉(zhuǎn)圈與冷卻效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-03-03

