PDA

View Full Version : [solved]How to copy files between folders



Cer3brus
02-09-2009, 03:10 PM
I was wondering if you could use a picture dialog to select an image, then copy the selected image to the folder of the program(that ran the picture dialog)'s exe.
Thanks in advance.

Traveler
02-09-2009, 07:04 PM
something like this?



procedure TForm1.Button1Click(Sender: TObject);
var filepath, pictureFileName, fileToCopy : string;
begin
filepath := ExtractFilePath(application.ExeName);
if (openPictureDialog1.Execute) then
begin
fileToCopy := openPictureDialog1.Filename;
pictureFileName := ExtractFileName(openPictureDialog1.Filename);

if copyFile(pchar(fileToCopy), pchar(filepath+pictureFileName),true) then
messagedlg('file succesfully copied', mtinformation, [mbok],0)
else
messagedlg('file was not copied!', mterror, [mbok],0)
end;
end;

Cer3brus
03-09-2009, 05:59 PM
Thanks!! Works wonderfully.
Just a small question, to rename the copied file, should I just change the PictureFileName variable?

Traveler
03-09-2009, 08:01 PM
Yes, that is correct. You do need to extract the original file extension though, if you want to change the filename.

Cer3brus
06-09-2009, 07:45 AM
Thank you. Is there some specific code required to extract the extension?

paul_nicholls
06-09-2009, 12:20 PM
Thank you. Is there some specific code required to extract the extension?


If you want to change the file extension of a filename just do something like so:

FileName := ChangeFileExt(FileName,'.bmp');
This will change the file extension to '.bmp' for example...

If you want to extract a file extension:

Ext := ExtractFileExt(FileName);

cheers,
Paul