How to list files from a folder in android firemonkey?

2

I have to create a way for the user to search for a backup generated by my system between the folders of the device, for this I thought of loading the folders in a listview that as clicked would enter the sub-folders. >

My problem is how to load the folders? I found some examples for Delphi , but I could not get them to work in Firemonkey .     

asked by anonymous 08.03.2017 / 20:11

1 answer

4

I was able to do it as follows

Listview and Label Components

Uses System.IOUtils

In the Form Show event

carregadiretorio(GetSharedDownloadsDir);

In the ItemClickEx event of Listview

if ListView1.Items[ListView1.ItemIndex].Detail='folder' then
  carregadiretorio(LbFolder.Text+PathDelim+ListView1.Items[ListView1.ItemIndex].Text)
else if ListView1.Items[ListView1.ItemIndex].Detail='voltar' then
  carregadiretorio(copy(ExtractFilePath(LbFolder.text), 0,Length(ExtractFilePath(LbFolder.text))-1));

and the procedure that loads the directory

procedure carregadiretorio(diretorio: string);
var
  listapastas, listaarquivos: TStringDynArray;
  pasta, arquivo: string;
  LItem: TListViewItem;
begin

    ListView1.Items.Clear;
    LbFolder.Text := diretorio;
    listapastas := TDirectory.GetDirectories(diretorio);
    listaarquivos := TDirectory.GetFiles(diretorio);
    ListView1.BeginUpdate;

    LItem := ListView1.Items.Add;
    LItem.Detail := 'voltar';
    LItem.Text := '..<<';

    for pasta in listapastas do
    begin
      //Carrega as Pastas
      LItem := ListView1.Items.Add;
      LItem.Detail := 'folder';
      LItem.Text := Copy(pasta, Length(ExtractFilePath(pasta))+1, Length(pasta));
    end;

    for arquivo in listaarquivos do
    begin
      //Carrega os Arquivos
      LItem := ListView1.Items.Add;
      LItem.Detail := 'file';
      LItem.Text := ExtractFileName(arquivo);
    end;

    ListView1.EndUpdate;
end;

Another solution follows the link link

    
08.03.2017 / 20:39