Solved

How to modify this code from TName?

Posted on 2006-11-14
5
218 Views
Last Modified: 2010-04-05
Hi my dear friends!

In reply to my question: How to copy folders to another location while adding the paths to a listbox?                     (ref. http://www.experts-exchange.com/......../Delphi/Q_22049426.html#17877306) TName answered me and provided a brilliant piece of code which took care of my concern.

Now  I want to modify it, here's what I would want:

Instead of selecting a folder, it should allow me to select a file. Instead of adding the folder reference to the listbox, it should add the file reference to the listbox. However,it should still copy the complete folder from where I selected the file.

So when I select d:\XXX\JJ\Vandaag zonder kleren\Jenna Jameson.jpg......this path should be added to my listbox while copying the entire directory d:\XXX\JJ\Vandaag zonder kleren\  to the new location where I copied the single file to.

Surely not all of this is abacadabra to me, but putting this whole thing back together...is.....I manage to select a file, add its reference to the listbox while copying the file as well. But how do I copy the entire directory where the file came from?

This is what I coded so far > b y using both the SelectDirectory and
the OpenDialog thing, I almost achieved my goal....

procedure TForm1.Button1Click(Sender: TObject);
var
  DirSelected, NewName: string;
begin
case CheckBox1.Checked of
True: Begin

  if SelectDirectory('Select a folder:', 'C:\', DirSelected) then begin
    NewName:='D:\Data\'+ExtractFileName(DirSelected);
    MoveDir(DirSelected,NewName);
  end
  else
    ShowMessage('No folder selected');
    end;
False: Begin
  if OpenDialog1.Execute then begin
    NewName := 'D:\Data\'+ExtractfileName(OPenDialog1.FileName);
   CopyFile(PChar(OpenDialog1.FileName),PChar(NewName), False);
   ListBox1.AddItem(NewName,Nil);
   CopyDir();
    end
    else
    ShowMessage('No file selected');
end
end;
end;



Kind regards,

Paul

ps working samples make me a happy man, if you need more info please ask!
0
Comment
Question by:PeterdeB
[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
  • 2
5 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17939017
Interesting files your testing with

d:\XXX\JJ\Vandaag zonder kleren\Jenna Jameson.jpg

:o)



> this path should be added to my listbox while copying the entire directory d:\XXX\JJ\Vandaag zonder kleren\  to the new location where I copied the single file to.

Why copy the file across first when you are going to copy the entire directory anyway.
This seems to be your problem.
Just extract the file path from the file selected and repeat as per before to copy the directory (and it will also copy the file across anyway)
0
 

Author Comment

by:PeterdeB
ID: 17939102
Hi Mike!

Well I need the file reference > into my listbox then copy the directory it resdes in.

Kind regards,

Paul
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 500 total points
ID: 17939234
Do you have to copy the file to the location to add it to the listbox though?
Take out the file copy, copy the entire directory, add the file path to the listbox

False: Begin
  if OpenDialog1.Execute then begin

    OldDir := ExtractFilePath( OPenDialog1.FileName);
    NewName := 'D:\Data\'+ExtractfileName(OPenDialog1.FileName);
    NewDir := ExtractFilePath( NewName);

    ListBox1.AddItem(NewName,Nil);

    CopyDir(OldDir, NewDir);

    end
    else
    ShowMessage('No file selected');
end
0
 

Author Comment

by:PeterdeB
ID: 17939250
>>
Oww ok now I see!

Kind regards,

Paul :-)
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17940492
No probs, glad I could help
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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