Results 1 to 6 of 6

Thread: [solved]How to copy files between folders

  1. #1

    [solved]How to copy files between folders

    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.

  2. #2

    Re: How to copy files between folders

    something like this?

    [code=pascal]
    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;
    [/code]

  3. #3

    Re: How to copy files between folders

    Thanks!! Works wonderfully.
    Just a small question, to rename the copied file, should I just change the PictureFileName variable?

  4. #4

    Re: How to copy files between folders

    Yes, that is correct. You do need to extract the original file extension though, if you want to change the filename.

  5. #5

    Re: How to copy files between folders

    Thank you. Is there some specific code required to extract the extension?

  6. #6

    Re: How to copy files between folders

    Quote Originally Posted by Cer3brus
    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:

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

    If you want to extract a file extension:

    [pascal]Ext := ExtractFileExt(FileName);[/pascal]

    cheers,
    Paul
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •