Solved

How to modify this code from TName?

Posted on 2006-11-14
5
217 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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