ImageEn, unit iexWPD

TIEPortableDevices.DeleteFromDevice

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
  sResultText: WideString;
  Idx: Integer;
  aObject: TIEWPDObject;
begin
  if lbxObjects.ItemIndex < 0 then
    exit;

  Idx := fPortableDevices.ObjectIDToIndex( lbxObjects.Items[ lbxObjects.ItemIndex ] );
  aObject := fPortableDevices.Objects[ Idx ];

  if MessageDlg( 'Are you sure you want to delete the file: ' + aObject.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, aObject.ID, True, sResultText ) > -1 then
      lbxObjects.Items.Delete( lbxObjects.ItemIndex );
    ShowMessage( sResultText );
  end;
end;

// Delete all displayed files
procedure TfrmMain.btnDeleteAllClick(Sender: TObject);
var
  sResultText: WideString;
  iCount: 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;
    iCount := IEPortableDevices.DeleteFromDevice( IEPortableDevices.ActiveDeviceID, lbxObjects.Items, True, sResultText );
    if iCount = -1 then
      ShowMessage( sResultText )
    else
    begin
      lbxObjects.Items.Clear;
      ShowMessage( format( '%d files were successfully deleted', [ iCount ] ));
    end;
  end;
end;