如何获取指定文件所在的目录名,或获取Program Files所在盘符?(50分)

Y

yitx

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获取指定文件所在的目录名,或获取Program Files所在盘符?
 
/取得系统System目录<br>var SystemDir:String;<br>begin<br>SetLength(SystemDir,144);<br>if GetSystemDirectory(Pchar(SystemDir),144)&lt;&gt;0 then<br>begin<br>SetLength(SystemDir,StrLen(Pchar(SystemDir)));<br>end;<br>end;<br><br>//取得当前目录<br>var CurrentDir:String;<br>begin<br>SetLength(CurrentDir,144);<br>if GetCurrentDirectory(144,Pchar(CurrentDir))&lt;&gt;0 then<br>begin<br>SetLength(CurrentDir,StrLen(Pchar(CurrentDir)));<br>end;<br>end;
 
function ExtractFilePath(const FileName: string): string;
 
shxcn: 这两个我也知道,谢谢了。
 
tseug:ExtractFilePath函数是从给定文件路径和文件名中获取路径,现在是只知道有这个文件<br>但不知道它在什么地方。
 
function GetSystemPath: string;<br>var<br>&nbsp; Buf: array[0..255] of Char;<br>begin<br>&nbsp; GetSystemDirectory(@Buf, 255);<br>&nbsp; Result := PathWithSlash(StrPas(@Buf));<br>end;<br><br>function GetWindowsPath: string;<br>var<br>&nbsp; Buf: array[0..255] of Char;<br>begin<br>&nbsp; GetWindowsDirectory(@Buf, 255);<br>&nbsp; Result := PathWithSlash(StrPas(@Buf));<br>end;<br>
 
我要的是Program Files所在盘符,不是要system/system32和windows目录
 
var<br>&nbsp; ss,RunPath;string<br>begin<br>&nbsp; ss:=uppercase(application.ExeName);<br>&nbsp; RunPath:=ExtractFilePath(ss);<br>end;
 
问题已自己解决!<br>感谢以上几位参与。
 
顶部