如何获得上级目录路径,如何获得program files的路径? (100分)

  • 主题发起人 主题发起人 homliu
  • 开始时间 开始时间
H

homliu

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获得已知目录的上级目录路径,如何获得系统盘的program files文件夹的路径?
 
这个问题看似简单,好象没有直接的。<br><br>脚本语言中好象有直接支持的。
 
本来可以对字符的处理来解决的,但我希望能通过一些api函数来处理。<br>但我对api懂的很少。
 
api好像没有直接的这样的函数,字符处理也很方便啊。<br>szFileName是你得到的获得系统盘的program files文件夹的路径,这个有API的<br><br>P := StrRScan(szFileName, '/');<br>p^:= #0;<br><br>这样处理一下就得到上一级目录了。要再上一级就再作一次。
 
通过API函数GetWindowsDirectory可以直接取得Windows所在的逻辑盘,<br>“program files”就在该盘下,路径名就是“program files”
 
Application.ExeName文件全名<br>ExtractFileDir( ExtractFileDir(Application.ExeName));文件上级目录<br>ExtractFileDir多用几次,是上级目录
 
正确的方法应该是用API函数<br>SHGetSpecialFolderLocation<br>或者用这个<br>SHGetSpecialFolderPath,后者的描述<br>function SHGetSpecialFolderPath(hwndOwner: HWND; lpszPath: PChar;<br>&nbsp; nFolder: Integer; fCreate: BOOL): BOOL; stdcall;<br><br>nFolder<br>&nbsp; Value specifying the folder to retrieve the location of. This parameter can be one of the following values:<br><br>CSIDL_BITBUCKET Recycle bin &amp;frac34; file system directory containing file objects in the user's recycle bin. The location of this directory is not in the registry; it is marked with the hidden and system attributes to prevent the user from moving or deleting it.<br>CSIDL_CONTROLS Control Panel &amp;frac34; virtual folder containing icons for the control panel applications.<br>CSIDL_DESKTOP Windows desktop &amp;frac34; virtual folder at the root of the name space.<br>CSIDL_DESKTOPDIRECTORY File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).<br>CSIDL_DRIVES My Computer &amp;frac34; virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.<br>CSIDL_FONTS Virtual folder containing fonts.<br>CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood.<br>CSIDL_NETWORK Network Neighborhood &amp;frac34; virtual folder representing the top level of the network hierarchy.<br>CSIDL_PERSONAL File system directory that serves as a common respository for documents.<br>CSIDL_PRINTERS Printers folder &amp;frac34; virtual folder containing installed printers.<br>CSIDL_PROGRAMS File system directory that contains the user's program groups (which are also file system directories).<br>CSIDL_RECENT File system directory that contains the user's most recently used documents.<br>CSIDL_SENDTO File system directory that contains Send To menu items.<br>CSIDL_STARTMENU File system directory containing Start menu items.<br>CSIDL_STARTUP File system directory that corresponds to the user's Startup program group.<br>CSIDL_TEMPLATES File system directory that serves as a common repository for document templates.
 
&gt;&gt;SHGetSpecialFolderLocation或者用这个SHGetSpecialFolderPath<br>其实这两个都不能得到楼主想要的东西。<br><br>&gt;&gt;如何获得已知目录的上级目录路径<br>没有现成的API,自己分析字符串就行了,因为路径是用“/”分隔的<br><br>&gt;&gt;如何获得系统盘的program files文件夹的路径? <br>先GetSystemDirectory取得系统所在的盘,然后加上Program Files就是你要的路径的<br>因为Program Files只会在根目录,不会跑到其他子目录下去的。<br>
 
后退
顶部