每議程煉-IOUtils 單元(5): TDirectory 的其他功能

來源:互聯網
上載者:User
TDirectory.CreateDirectory();     {建立新目錄}


TDirectory.Exists();              {判斷檔案夾是否存在}


TDirectory.IsEmpty();            {判斷檔案夾是否為空白}


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();



DEMO下載:IOUnit5






代碼部分://IOUtils 單元(5): TDirectory 的其他功能unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)mmo1: TMemo;btn1: TButton;btn2: TButton;btn3: TButton;procedure btn1Click(Sender: TObject);procedure btn2Click(Sender: TObject);procedure btn3Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}uses IOUtils, Types, TypInfo;//TDirectory.GetLogicalDrives; {擷取磁碟機列表}procedure TForm1.btn1Click(Sender: TObject);vars: string;arr: TStringDynArray;beginarr := TDirectory.GetLogicalDrives;mmo1.Clear;for s in arr do mmo1.Lines.Add(s);end;//TDirectory.GetAttributes(); {擷取檔案夾屬性, 譬如唯讀、存檔等}procedure TForm1.btn2Click(Sender: TObject);varfas: TFileAttributes;fa: TFileAttribute;beginfas := TDirectory.GetAttributes(‘c:/Windows’);mmo1.Clear;for fa := Low(TFileAttribute) to High(TFileAttribute) doif fa in fas then mmo1.Lines.Add(GetEnumName(TypeInfo(TFileAttribute), Ord(fa)));end;procedure TForm1.btn3Click(Sender: TObject);constpath = ‘c:/temp/ABC’;beginTDirectory.CreateDirectory(path);TDirectory.SetAttributes(path, [TFileAttribute.faHidden]);ShowMessage(‘建立並隱藏檔案夾成功/’);end;end.//表單部分object Form1: TForm1Left = 0Top = 0Caption = #24858#20154#31508#35760′-http://www.foolcode.com’ClientHeight = 290ClientWidth = 456Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = ‘Tahoma’Font.Style = []OldCreateOrder = FalsePixelsPerInch = 96TextHeight = 13object mmo1: TMemoLeft = 0Top = 0Width = 457Height = 233ImeName = #20013#25991′(‘#31616#20307′) – ‘#25628#29399#25340#38899#36755#20837#27861Lines.Strings = (‘mmo1′)TabOrder = 0endobject btn1: TButtonLeft = 40Top = 255Width = 97Height = 25Caption = ‘GetLogicalDrives’TabOrder = 1OnClick = btn1Clickendobject btn2: TButtonLeft = 168Top = 255Width = 97Height = 25Caption = ‘GetAttributes’TabOrder = 2OnClick = btn2Clickendobject btn3: TButtonLeft = 304Top = 255Width = 89Height = 25Caption = ‘CreateDirectory’TabOrder = 3OnClick = btn3Clickendend

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.