如何将绝对路径转为相对路径

来源:百度知道 编辑:UC知道 时间:2024/05/18 09:24:49

像这样:
char * path;
CString c_path;
path=new char[200];
GetModuleFileName(AfxGetInstanceHandle(),path,200);
c_path=path;
AfxMessageBox(c_path);
就可以了!
如果需要是WEB应用的目录下就很好办啊。假设web根目录为:c:\www,而DB放在www目录下的话则可以这样。
System.AppDomain.CurrentDomain.BaseDirectory.ToString() + ConfigurationManager.AppSettings["dbPath"]就可以了

在a.asp在d:\web\hello\ 下
a.asp的绝对路径就是d:\web\hello\a.asp
如果把一个域名XXX.COM绑定到hello
那么
http://XXX.COM/a.asp
也就是绝对路径!
如果把一个域名XXX.COM绑定到web
那么
http://XXX.COM/hello/a.asp
也就是绝对路径!
最好看看你IIS中设置的主目录是哪个

App.Path\
用这个东西代替你绝对路径中文件前的那一大段。例如:
F:\游戏\魔兽\1.20升级补丁.exe
相对路径就是
App.Path\1.20升级补丁.exe