Solved

How to modify this code from TName?

Posted on 2006-11-14
5
215 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: sending SMS on android platform 1 34
scroll down TListBox component in Delphi 1 19
MS Access from Delphi 31 60
DBCtrlGrid, Delphi, Scroll 7 26
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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