Solved

How to modify this code from TName?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now