PeterdeB
asked on
How to modify this code from TName?
Hi my dear friends!
In reply to my question: How to copy folders to another location while adding the paths to a listbox? (ref. https://www.experts-exchange.com/questions/22049426/How-to-copy-folders-to-another-location-while-adding-the-paths-to-a-listbox.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\'+Extrac tFileName( DirSelecte d);
MoveDir(DirSelected,NewNam e);
end
else
ShowMessage('No folder selected');
end;
False: Begin
if OpenDialog1.Execute then begin
NewName := 'D:\Data\'+ExtractfileName (OPenDialo g1.FileNam e);
CopyFile(PChar(OpenDialog1 .FileName) ,PChar(New Name), False);
ListBox1.AddItem(NewName,N il);
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!
In reply to my question: How to copy folders to another location while adding the paths to a listbox? (ref. https://www.experts-exchange.com/questions/22049426/How-to-copy-folders-to-another-location-while-adding-the-paths-to-a-listbox.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
var
DirSelected, NewName: string;
begin
case CheckBox1.Checked of
True: Begin
if SelectDirectory('Select a folder:', 'C:\', DirSelected) then begin
NewName:='D:\Data\'+Extrac
MoveDir(DirSelected,NewNam
end
else
ShowMessage('No folder selected');
end;
False: Begin
if OpenDialog1.Execute then begin
NewName := 'D:\Data\'+ExtractfileName
CopyFile(PChar(OpenDialog1
ListBox1.AddItem(NewName,N
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!
ASKER
Hi Mike!
Well I need the file reference > into my listbox then copy the directory it resdes in.
Kind regards,
Paul
Well I need the file reference > into my listbox then copy the directory it resdes in.
Kind regards,
Paul
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>
Oww ok now I see!
Kind regards,
Paul :-)
Oww ok now I see!
Kind regards,
Paul :-)
No probs, glad I could help
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)