Delphi 跨平台获取文件列表


本文整理自网络,侵删。

 
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.ListView.Types, FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
  FMX.ListView, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit, FMX.Media,
  FMX.Ani, FMX.Objects, FMX.Layouts;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    MediaPlayer1: TMediaPlayer;
    txtBilgi: TText;
    Layout1: TLayout;
    Image1: TImage;
    FloatAnimation1: TFloatAnimation;
    procedure FormCreate(Sender: TObject);
    procedure ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem);
    procedure Image1Click(Sender: TObject);
  private
    function GetArsHedef: String;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

Uses System.IOUtils;

procedure TForm1.FormCreate(Sender: TObject);
begin
  txtBilgi.Text := TPath.GetDirectoryName(GetArsHedef());
  FloatAnimation1.StartValue := Form1.Width;
{$IFDEF ANDROID}
  FullScreen := True;
{$ENDIF}
end;

function TForm1.GetArsHedef(): String;
const
  DosyaAdi: String = 'Gorusme.mp3';
begin
{$IFDEF ANDROID}
  Result := TPath.Combine(TPath.GetSharedMusicPath, DosyaAdi);
{$ELSE}
{$IFDEF IOS}    { /private/var/mobile/Applications/<application ID> }
  Result := TPath.GetHomePath + '/Documents/' + DosyaAdi;
{$ELSE}    { Win=C:\Users\Public\Music }
  Result := TPath.Combine(TPath.GetSharedMusicPath, DosyaAdi);
{$ENDIF}
{$ENDIF}
end;

procedure TForm1.Image1Click(Sender: TObject);
var
  Konum: string;
  AramaSecenegi: TSearchOption;
begin
  Konum := TPath.GetDirectoryName(GetArsHedef());
  if not TDirectory.Exists(Konum) then
  begin
    ShowMessage('');
    Exit;
  end;

  AramaSecenegi := TSearchOption.soAllDirectories;
  // LSearchOption := TSearchOption.soTopDirectoryOnly;
  ListView1.Items.Clear;
  for Konum in TDirectory.GetFiles(Konum, '*.mp3', AramaSecenegi) do
    With ListView1.Items.Add do
    begin
      Text := (ListView1.Items.Count).ToString + ' - ' + TPath.GetFileName(Konum);
      Detail := Konum;
    end;
end;

procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem);
begin
  txtBilgi.Text := ': ' + AItem.Text;
  MediaPlayer1.FileName := AItem.Detail;
  MediaPlayer1.Play;
  FloatAnimation1.StopValue := -txtBilgi.Width - Image1.Width;
  FloatAnimation1.Start;
end;

end.

相关阅读 >>

Delphi 如何从dll中检索导出函数的列表

Delphi源码基础源码-按下回车取得焦点

Delphi中关于字符串的操作

Delphi firedac fdconnection 事务

firemonkey使用android的路径信息

Delphi中url的编码与解码,即urlencode的使用

Delphi 3句话绕过xxx拦截删除桌面快捷方式

Delphi ansicontainstext 是否包含子串

Delphi 自带gif控件的动画图片加载和播放

Delphi指针

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...