Delphi – 如何获取目录的所有文件的列表

前端之家收集整理的这篇文章主要介绍了Delphi – 如何获取目录的所有文件的列表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用delphi,当我执行openpicturedialog时,我想要一个目录的所有文件的列表.

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.

您甚至可以建议我从TOpenDialog的FileName属性获取目录名称
谢谢.

解决方法

@Himadri,OpenPictureDialog的主要目标不是选择一个目录,反正如果你使用这个对话框的另一个目的,你可以试试这个代码.
  1. Var
  2. Path : String;
  3. SR : TSearchRec;
  4. DirList : TStrings;
  5. begin
  6. if OpenPictureDialog1.Execute then
  7. begin
  8. Path:=ExtractFileDir(OpenPictureDialog1.FileName); //Get the path of the selected file
  9. DirList:=TStringList.Create;
  10. try
  11. if FindFirst(Path + '*.*',faArchive,SR) = 0 then
  12. begin
  13. repeat
  14. DirList.Add(SR.Name); //Fill the list
  15. until FindNext(SR) <> 0;
  16. FindClose(SR);
  17. end;
  18.  
  19. //do your stuff
  20.  
  21. finally
  22. DirList.Free;
  23. end;
  24. end;
  25.  
  26. end;

猜你在找的Delphi相关文章