Solved

How to Copy a file from ShellListView1 to ShellListView2?

Posted on 2010-09-10
3
641 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 4 hours left to enroll

623 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