TDirectory.Delete 创建删除目录简单示例

使用函数:

  1.System.IOUtils.TDirectory.CreateDirectory//创建目录

  2.System.IOUtils.TDirectory.Exists          //目录是否存在

  3.System.IOUtils.TDirectory.Delete             //删除目录

示例:

TDirectory.Delete 创建删除目录简单示例

代码:

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.IOUtils; type
TForm1 = class(TForm)
Button_Start: TButton;
Edit_dir: TEdit;
CheckBox_StayOnTop: TCheckBox;
procedure Button_StartClick(Sender: TObject);
procedure CheckBox_StayOnTopClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button_StartClick(Sender: TObject);
const
ForceTop = ;
var
dir: string;
tmp: Integer;
isRecursive: Boolean; // 是否递归??
begin
dir := Edit_dir.Text; if not TDirectory.Exists(dir) then
begin
if MessageBox(, '文件不存在是否要创建?', '提示', MB_YESNO + ForceTop) = IDNO then
Exit;
try
TDirectory.CreateDirectory(dir);
except
on e: Exception do
begin
MessageDlg('创建失败!' + e.Message, mtError, [mbok], );
Exit;
end;
end; end
else
begin
tmp := MessageBox(, ('文件已存在是否要删除?' + # + '是->普通删除' + # + '否->递归删除'
+ # + '取消->无作为'), '提示', MB_YESNOCANCEL + ForceTop);
case tmp of
IDCANCEL:
Exit;
IDYES:
isRecursive := False;
IDNO:
isRecursive := True;
end;
try
TDirectory.Delete(dir, isRecursive);
except
on e1: Exception do
begin
MessageDlg('删除失败!' + e1.Message, mtError, [mbok], );
Exit;
end;
end;
end; end; procedure TForm1.CheckBox_StayOnTopClick(Sender: TObject);
begin
if CheckBox_StayOnTop.Checked then
Form1.FormStyle := TFormStyle.fsStayOnTop
else
Form1.FormStyle := TFormStyle.fsNormal;
end; end.
上一篇:动态规划之最长公共子序列(LCS)


下一篇:MSIL学习------从HelloWorld开始