TDirectory.CreateDirectory(); {建立新目錄}
TDirectory.Exists(); {判斷文件夾是否存在}
TDirectory.IsEmpty(s1); {判斷文件夾是否為空}
TDirectory.Copy(); {復制文件夾}
TDirectory.Move(); {移動文件夾}
TDirectory.Delete(); {刪除文件夾, 第二個參數為 True 可刪除非空文件夾}
TDirectory.GetDirectoryRoot(); {獲取目錄的根盤符, 如: C:\}
TDirectory.GetCurrentDirectory; {獲取當前目錄}
TDirectory.SetCurrentDirectory(); {設置當前目錄}
TDirectory.GetLogicalDrives; {獲取驅動器列表; 下有舉例}
TDirectory.GetAttributes(); {獲取文件夾屬性, 譬如只讀、存檔等; 下有舉例}
TDirectory.SetAttributes(); {設置文件夾屬性; 下有舉例}
{獲取、設置文件建立時間、修改時間、讀取時間}
TDirectory.GetCreationTime();
TDirectory.SetCreationTime();
TDirectory.GetLastWriteTime();
TDirectory.SetLastWriteTime();
TDirectory.GetLastAccessTime();
TDirectory.SetLastAccessTime();
{使用 Utc 時間格式讀取或設置}
TDirectory.GetCreationTimeUtc();
TDirectory.SetCreationTimeUtc();
TDirectory.GetLastWriteTimeUtc();
TDirectory.SetLastWriteTimeUtc();
TDirectory.GetLastAccessTimeUtc();
TDirectory.SetLastAccessTimeUtc();
測試代碼:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses IOUtils, Types, TypInfo;
//TDirectory.GetLogicalDrives; {獲取驅動器列表}
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
arr: TStringDynArray;
begin
arr := TDirectory.GetLogicalDrives;
Memo1.Clear;
for s in arr do Memo1.Lines.Add(s);
end;
//TDirectory.GetAttributes(); {獲取文件夾屬性, 譬如只讀、存檔等}
procedure TForm1.Button2Click(Sender: TObject);
var
fas: TFileAttributes;
fa: TFileAttribute;
begin
fas := TDirectory.GetAttributes('c:\Windows');
Memo1.Clear;
for fa := Low(TFileAttribute) to High(TFileAttribute) do
if fa in fas then Memo1.Lines.Add(GetEnumName(TypeInfo(TFileAttribute), Ord(fa)));
end;
//TDirectory.SetAttributes(); {設置文件夾屬性, 這裡是設置為隱藏}
procedure TForm1.Button3Click(Sender: TObject);
const
path = 'c:\temp\ABC';
begin
TDirectory.CreateDirectory(path);
TDirectory.SetAttributes(path, [TFileAttribute.faHidden]);
end;
end.