TIEPortableDevices.DeleteFromDevice
Declaration
function DeleteFromDevice(const sDeviceID, sObjectID: WideString; bDeleteSubObjects: Boolean = True): Integer; overload;
function DeleteFromDevice(const sDeviceID, sObjectID: WideString; bDeleteSubObjects: Boolean; var sResultText: WideString): Integer; overload;
function DeleteFromDevice(const sDeviceID: WideString; ssObjectIDs: TStrings; bDeleteSubObjects: Boolean = True): Integer; overload;
function DeleteFromDevice(const sDeviceID: WideString; ssObjectIDs: TStrings; bDeleteSubObjects: Boolean; var sResultText: WideString): Integer; overload;
function DeleteFromDevice(Indexes: TStrings; bDeleteSubObjects: Boolean = True): Integer; overload;
Description
Delete files or folders from a device.
| Parameter | Description |
| sDeviceID | The ID of the device to delete from (e.g. ActiveDeviceID) |
| sObjectID or ssObjectIDs | The ID(s) of the file(s) or folder(s) to delete (e.g. ActiveFolderID) |
| bDeleteSubObjects | If sObjectID is a folder, then enabling bDeleteSubObjects will also delete all objects in sub-folders |
| sResultText | Is filled with a response from the WPD API regarding the success or failure of the action (e.g. "1 file was successfully deleted) |
Result is a count of the files deleted, or -1 if an error was encountered.
Examples
// Delete the current folder and all sub-folders
IEPortableDevices.DeleteFromDevice( IEPortableDevices.ActiveDeviceID, IEPortableDevices.ActiveFolderID, True );
// Delete the selected file or folder
procedure TfrmMain.btnDeleteFromDeviceClick(Sender: TObject);
var
ResultText: WideString;
idx: Integer;
obj: TIEWPDObject;
begin
if lbxObjects.ItemIndex < 0 then
exit;
idx := fPortableDevices.ObjectIDToIndex( lbxObjects.Items[ lbxObjects.ItemIndex ] );
obj := fPortableDevices.Objects[ idx ];
if MessageDlg( 'Are you sure you want to delete the file: ' + obj.Filename, mtConfirmation, [ mbYes, mbNo ], 0 ) = mrYes then
begin
ShowTempHourglass;
// Note: bDeleteSubObjects is True, so if a folder is selected it will also delete any files in it
if IEPortableDevices.DeleteFromDevice( IEPortableDevices.ActiveDeviceID, obj.ID, True, ResultText ) > -1 then
lbxObjects.Items.Delete( lbxObjects.ItemIndex );
ShowMessage( ResultText );
end;
end;
// Delete all displayed files
procedure TfrmMain.btnDeleteAllClick(Sender: TObject);
var
ResultText: WideString;
cnt: Integer;
begin
if lbxObjects.Items.Count = 0 then
exit;
if MessageDlg( Format( 'Are you sure you want to delete the %d files in this folder?', [ lbxObjects.Items.Count ] ),
mtConfirmation, [ mbYes, mbNo ], 0 ) = mrYes then
begin
ShowTempHourglass;
cnt := IEPortableDevices.DeleteFromDevice( IEPortableDevices.ActiveDeviceID, lbxObjects.Items, True, ResultText );
if cnt = -1 then
ShowMessage( ResultText )
else
begin
lbxObjects.Items.Clear();
ShowMessage( Format( '%d files were successfully deleted', [ cnt ] ));
end;
end;
end;