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


    使用函数:

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

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

      3.System.IOUtils.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 = 262144;
    var
        dir: string;
        tmp: Integer;
        isRecursive: Boolean; // 是否递归??
    begin
        dir := Edit_dir.Text;
    
        if not TDirectory.Exists(dir) then
        begin
            if MessageBox(0, '文件不存在是否要创建?', '提示', MB_YESNO + ForceTop) = IDNO then
                Exit;
            try
                TDirectory.CreateDirectory(dir);
            except
                on e: Exception do
                begin
                    MessageDlg('创建失败!' + e.Message, mtError, [mbok], 0);
                    Exit;
                end;
            end;
    
        end
        else
        begin
            tmp := MessageBox(0, ('文件已存在是否要删除?' + #13 + '是->普通删除' + #13 + '否->递归删除'
              + #13 + '取消->无作为'), '提示', 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], 0);
                    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.
  • 相关阅读:
    12.静态目录
    11.Git线上操作
    10.分离的前后台交互
    09.后台主页应用
    08.前端主页
    爬虫介绍
    python2与python3爬虫中get与post对比
    HTML+CSS+JavaScript
    数据库 Mysql-mongodb-redis
    时频工具箱介绍与使用
  • 原文地址:https://www.cnblogs.com/cause/p/3496264.html
Copyright © 2020-2023  润新知