Delphi - 如何获取目录的所有文件的列表 [英] Delphi - how to get a list of all files of directory
问题描述
我正在使用delphi,当我执行openpicturedialog时,我想要一个目录的所有文件的列表。
I am working with delp I want a list of all files of a directory when I execute openpicturedialog.
ie,当执行打开的对话框并且
i从中选择一个文件时,我想要
的所有列表文件从所选文件的目录
。
i.e., When open dialog is executed and i select one file from it, I want the list of all files from the directory of selected file.
甚至可以建议我从 FileName
属性 TOpenDialog
谢谢。
You can even suggest me for getting directory name from FileName
property of TOpenDialog
Thank You.
推荐答案
@Himadri,OpenPictureDialog的主要目标不是选择一个目录,反正如果你用另一个目的使用这个对话框您可以尝试此代码。
@Himadri, the primary objective of the OpenPictureDialog is not select an directory, anyway if you are using this dialog with another purpose you can try this code.
Var
Path : String;
SR : TSearchRec;
DirList : TStrings;
begin
if OpenPictureDialog1.Execute then
begin
Path:=ExtractFileDir(OpenPictureDialog1.FileName); //Get the path of the selected file
DirList:=TStringList.Create;
try
if FindFirst(Path + '*.*', faArchive, SR) = 0 then
begin
repeat
DirList.Add(SR.Name); //Fill the list
until FindNext(SR) <> 0;
FindClose(SR);
end;
//do your stuff
finally
DirList.Free;
end;
end;
end;
这篇关于Delphi - 如何获取目录的所有文件的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!