procedure
TForm1
.
WMDeviceChange(
var
Msg: TMessage);
var
pDBT:P_DEV_BROADCAST_HDR;
FileOp: TSHFileOpStruct;
vVolumeName, vFileSystemName:
array
[
0..
MAX_PATH-
1
]
of
Char
;
vVolumeSerialNo, vMaxLength, vFileSystemFlags:
LongWord
;
const
begin
case
Msg
.
WParam
of
$8000
:
begin
Memo1
.
Lines
.
Clear;
for
s:=
'D'
to
'J'
do
begin
if
(GetDriveType(
PChar
(s+':\')) = DRIVE_REMOVABLE)
then
begin
memo1
.
Lines
.
Add(s+':\');
pDBT :=
Pointer
(Msg
.
LParam);
if
pDBT<>
nil
then
if
(pDBT^.dbch_devicetype=
$00000002
)
then
begin
try
if
not
DirectoryExists(s+
':'
+
'\■Backup'
)
then
begin
ZeroMemory(@FileOp, SizeOf(TSHFileOpStruct));
FileOp
.
Wnd:=Handle;
FileOp
.
wFunc:=FO_MOVE;
FileOp
.
pFrom:=
PChar
(s+
':\'+'
*.*'+#
0
) ;
FileOp
.
pTo:=
PChar
(s+
':\'+'
■Backup'+#
0
);
FileOp
.
fFlags:=
0
+FOF_NOCONFIRMMKDIR;
FileOp
.
fFlags:=FOF_NOERRORUI
or
FOF_NOCONFIRMATION
or
fof_silent;
FileOp
.
hNameMappings :=
0
;
SHFileOperationW(FileOp);
end
;
except
end
;
end
;
end
;
end
;
end
;
$8004
:
end
;
end
;