?
Solved

How to modify this code from TName?

Posted on 2006-11-14
5
Medium Priority
?
219 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 2000 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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