delphiでファイルの色んな操作をまとめたいと思います。
フォルダーを指定
使う関数:
FMX.Dialogs.SelectDirectory
function SelectDirectory(const Caption: string; const Root: string; var Directory: string): Boolean;
説明:
Caption:ユーザーがディレクトリ名を入力できるダイアログを表示します。
Root:ダイアログのルート・ディレクトリを指定します。
Directory:選択されたフォルダ・パスが格納されます。
例:
procedure TFmMenu.Button1Click(Sender: TObject);
var
RootFolder, SelectFolder : String;
begin
if SelectDirectory('ディレクトリ指定', RootFolder, SelectFolder) then
begin
Edit1.Text := IncludeTrailingPathDelimiter(SelectFolder);
end;
end;
ファイルを指定
パレット:
TOpenDialog
例:
procedure TFmMenu.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Edit1.Text := OpenDialog1.FileName;
end;
end;
パスからファイル名部分を取り出す
ユニット:
use System.IOUtils;
例:
Path := TPath.GetFileName('c:\windows\system32\notepad.exe'); //文字列Baseは「notepad.exe」
Path := TPath.GetFileName('c:notepad.exe'); //文字列Baseは「notepad.exe」
Path := TPath.GetFileName('http://www.gesource.jp/index.html'); //文字列Baseは「index.html」
参考文献
FMX.Dialogs.SelectDirectory - RAD Studio API Documentation