Repository navigation
Expand file tree
/
Copy pathMainUnit.pas
More file actions
82 lines (68 loc) · 1.73 KB
/
Copy pathMainUnit.pas
File metadata and controls
82 lines (68 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
unit MainUnit;
interface
uses
Winapi.Windows,
Winapi.Messages,
Winapi.ShellAPI,
System.SysUtils,
System.Classes,
Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls, Vcl.Controls, Vcl.ExtCtrls;
type
TForm2 = class(TForm)
Shape1: TShape;
Label1: TLabel;
private
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
procedure DoDeleteFolder(const FolderName: string);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
constructor TForm2.Create(AOwner: TComponent);
begin
inherited;
// Enable drag-and-drop from Explorer
DragAcceptFiles(Handle, True);
end;
destructor TForm2.Destroy;
begin
// Disable drag-and-drop
DragAcceptFiles(Handle, False);
inherited;
end;
procedure TForm2.DoDeleteFolder(const FolderName: string);
begin
ShellExecute(0, 'open', 'cmd.exe', PWideChar('/C ' + // Command
'del /f /s /q "' + FolderName + '" > nul ' +
'&& rmdir /s /q "' + FolderName + '"'), nil, SW_SHOWNORMAL);
end;
procedure TForm2.WMDropFiles(var Msg: TWMDropFiles);
var
Count: Integer;
FileName: array[0..MAX_PATH] of Char;
begin
try
Count := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
if Count > 0 then
begin
// Get the first dropped item
DragQueryFile(Msg.Drop, 0, FileName, MAX_PATH);
// Check if it's a folder
if DirectoryExists(FileName) then
begin
if MessageDlg('Delete folder ' + FileName + ' and all files and subfolders in it? This cannot be undone.',
mtWarning, [mbYes, mbCancel], 0) = mrYes then
DoDeleteFolder(FileName);
end;
end;
finally
DragFinish(Msg.Drop);
end;
end;
end.