Solved

How to Copy a file from ShellListView1 to ShellListView2?

Posted on 2010-09-10
3
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
Tom earned 250 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 250 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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