Solved

How to Copy a file from ShellListView1 to ShellListView2?

Posted on 2010-09-10
3
621 Views
Last Modified: 2012-05-10
Hi, how do I move/copy a file from ShellListView1 to ShellListView2 and also a function of the from and to location?
0
Comment
Question by:eNarc
3 Comments
 
LVL 9

Accepted Solution

by:
Tom earned 250 total points
Comment Utility
Maybe this question/answere will lead you in the right direction?
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21085300.html
0
 
LVL 5

Author Comment

by:eNarc
Comment Utility
Meant to say Drag a file from ShellListView1 to ShellListView2?
0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 250 total points
Comment Utility
Here is the code to do that, remember to set DragMode for ShellListView1 to dmAutomatic


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ShellCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    ShellListView1: TShellListView;
    ShellListView2: TShellListView;
    ShellComboBox1: TShellComboBox;
    ShellComboBox2: TShellComboBox;
    procedure ShellListView2DragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure ShellListView2DragDrop(Sender, Source: TObject; X,
      Y: Integer);
  private
    procedure CopySelectedFile(const AFileName, ADestinationFolder: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ShellListView2DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept := True;
end;

procedure TForm1.ShellListView2DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  CopyTo: string;
  DestinationItem, SourceItem: TListItem;
  WorkFolder: TShellFolder;
begin
  DestinationItem := (Sender as TShellListView).GetItemAt(X, Y);
  if Assigned(DestinationItem) then
  begin
    WorkFolder := (Sender as TShellListView).Folders[DestinationItem.Index];
    if WorkFolder.IsFolder then
      CopyTo := WorkFolder.PathName
    else
      CopyTo := ExtractFileDir(WorkFolder.PathName);

    SourceItem := (Source as TShellListView).Selected;
    WorkFolder := (Source as TShellListView).Folders[SourceItem.Index];

    if not WorkFolder.IsFolder then //unless you wan't to copy all files in the folder
      CopySelectedFile(WorkFolder.PathName, CopyTo);
  end;
end;

procedure TForm1.CopySelectedFile(const AFileName, ADestinationFolder: string);
var
  DestinationFile: string;
begin
  DestinationFile := IncludeTrailingPathDelimiter(ADestinationFolder) + ExtractFileName(AFileName);
  Windows.CopyFile(PChar(AFileName), PChar(DestinationFile), True);

  //if you want to move the file
  //Windows.MoveFile(PChar(AFileName), PChar(DestinationFile));
end;

end.

//Form
object Form1: TForm1
  Left = 363
  Top = 130
  Width = 927
  Height = 582
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ShellListView1: TShellListView
    Left = 32
    Top = 40
    Width = 873
    Height = 161
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfDesktop'
    ShellComboBox = ShellComboBox2
    Sorted = True
    DragMode = dmAutomatic
    ReadOnly = False
    HideSelection = False
    TabOrder = 0
    ViewStyle = vsReport
  end
  object ShellListView2: TShellListView
    Left = 32
    Top = 240
    Width = 873
    Height = 193
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfDesktop'
    ShellComboBox = ShellComboBox2
    Sorted = True
    ReadOnly = False
    HideSelection = False
    OnDragDrop = ShellListView2DragDrop
    OnDragOver = ShellListView2DragOver
    TabOrder = 1
    ViewStyle = vsReport
  end
  object ShellComboBox1: TShellComboBox
    Left = 32
    Top = 8
    Width = 865
    Height = 22
    Root = 'rfDesktop'
    ShellListView = ShellListView1
    UseShellImages = True
    DropDownCount = 8
    TabOrder = 2
  end
  object ShellComboBox2: TShellComboBox
    Left = 32
    Top = 216
    Width = 865
    Height = 22
    Root = 'rfDesktop'
    ShellListView = ShellListView2
    UseShellImages = True
    DropDownCount = 8
    TabOrder = 3
  end
end
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now