?
Solved

How to Copy a file from ShellListView1 to ShellListView2?

Posted on 2010-09-10
3
Medium Priority
?
667 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 10

Accepted Solution

by:
Tom earned 1000 total points
ID: 33650586
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
ID: 33650621
Meant to say Drag a file from ShellListView1 to ShellListView2?
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 1000 total points
ID: 33651465
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

579 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