Delphi浏览文件夹

来源:互联网 发布:系统自动还原软件 编辑:程序博客网 时间:2024/05/21 14:42
Delphi如何实现浏览文件夹,并得出所选择的文件夹名:
SelectDirectory函数(FileCtrl单元)
1、function SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; overload;
2、function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;
注意:使用前请uses FileCtrl;
第1种调用格式示例为:
const
  sCaption = '文件夹';       //弹出框标题名(非弹出框窗体名)
  sRoot = '';                    //初始文件夹(如'C:/','D:/DownLoad'等, 不存在则从桌面)
var
  sDir: string;
begin
  if SelectDirectory(sCaption, sRoot, sDir) then
  //已返回所选文件夹路径给sDir,自行处理
end;
结果下图:
 
第2种调用格式示例为:
const
  SELDIRHELP = 1000;
var
  sDir: string;            //初始文件夹(如'C:/','D:/DownLoad'等)
begin
  sDir := '';
  if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], SELDIRHELP) then
    //已返回所选文件夹路径给sDir,自行处理
end;
结果下图: