delphi IOUtils 单元(5): TDirectory.TDirectory 的其他功能


本文整理自网络,侵删。

 
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();
 
代码部分://IOUtils 单元(5): TDirectory 的其他功能unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = 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;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses IOUtils, Types, TypInfo;

//TDirectory.GetLogicalDrives; {获取驱动器列表}
procedure TForm1.btn1Click(Sender: TObject);
var
s: string;
arr: TStringDynArray;
begin
arr := TDirectory.GetLogicalDrives;
mmo1.Clear;
for s in arr do mmo1.Lines.Add(s);
end;

//TDirectory.GetAttributes(); {获取文件夹属性, 譬如只读、存档等}
procedure TForm1.btn2Click(Sender: TObject);
var
fas: TFileAttributes;
fa: TFileAttribute;
begin
fas := TDirectory.GetAttributes('c:Windows');
mmo1.Clear;
for fa := Low(TFileAttribute) to High(TFileAttribute) do
if fa in fas then mmo1.Lines.Add(GetEnumName(TypeInfo(TFileAttribute), Ord(fa)));
end;

procedure TForm1.btn3Click(Sender: TObject);
const
path = 'c:tempABC';
begin
TDirectory.CreateDirectory(path);
TDirectory.SetAttributes(path, [TFileAttribute.faHidden]);
ShowMessage('创建并隐藏文件夹成功');
end;

end.
\窗体部分
object Form1: TForm1
Left = 0
Top = 0
Caption = #24858#20154#31508#35760'-http://www.foolcode.com'
ClientHeight = 290
ClientWidth = 456
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object mmo1: TMemo
Left = 0
Top = 0
Width = 457
Height = 233
ImeName = #20013#25991'('#31616#20307') - '#25628#29399#25340#38899#36755#20837#27861
Lines.Strings = (
'mmo1')
TabOrder = 0
end
object btn1: TButton
Left = 40
Top = 255
Width = 97
Height = 25
Caption = 'GetLogicalDrives'
TabOrder = 1
OnClick = btn1Click
end
object btn2: TButton
Left = 168
Top = 255
Width = 97
Height = 25
Caption = 'GetAttributes'
TabOrder = 2
OnClick = btn2Click
end
object btn3: TButton
Left = 304
Top = 255
Width = 89
Height = 25
Caption = 'CreateDirectory'
TabOrder = 3
OnClick = btn3Click
end
end

相关阅读 >>

Delphi listview的用法

Delphi xe7 android 实现的在线更新app的一个程序

idhttp访问网页出现socket error #10054错误

Delphi fmx app 设置 程序图标,闪屏,程序名

Delphi 实现窗体倒计时进度条显示

Delphi xe 可用的md5算法

Delphi unigui 控件动画

Delphi webbroker 上传文件

Delphi-xe5-开发 android uri简介

Delphi 读cpu串号的代码

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



打赏

取消

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

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

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

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

评论

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