With Inno Setup how can I rename and copy a file a user chooses (an image) to the program files directory

John Batdorf

I understand how to create a custom wizard page. Just not sure how to add a file picker, and restrict it to a .jpg file type. I have a code section that runs at the end of the installation to take user defined input during setup and modify a settings file, just need to understand how to take the value of a file they choose during a setup screen step, and then copy it, rename it, and dump it into the program files folder.

TLama

How to create a filtered input file wizard page item ?

For the purpose of file selections you should use a separate input file wizard page, which you can create by the CreateInputFilePage. Then, the Add method of the TInputFileWizardPage page object class contains the AFilter parameter where you can specify the filter for files that can be selected by its associated file open dialog. In this example we allow the users select only *.jpg files:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
var
  InputPage: TInputFileWizardPage;

procedure InitializeWizard;
begin
  // create the input file wizard page
  InputPage := CreateInputFilePage(wpWelcome, 'Caption', 'Description',
    'SubCaption');
  // and insert one item in which the user will be restricted to select
  // only *.jpg files
  InputPage.Add('Prompt', 'JPG files (*.jpg)|*.jpg', '.jpg');
end;

How to manually invoke a filtered file open dialog ?

If that input file wizard page doesn't fit to your design and you want to make your own, then you need the GetOpenFileName function to show an open file dialog. Even this function contains a parameter where you can specify the filter string. In this case it is the Filter parameter. In this script example is shown, how to invoke a file open dialog with a *.jpg file filter:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
procedure InitializeWizard;
var
  FileName: string;
begin
  if GetOpenFileName('Prompt', FileName, 'C:\InitialDirectory',
    'JPG files (*.jpg)|*.jpg', '.jpg')
  then
    MsgBox(Format('Selected file: %s', [FileName]), mbInformation, MB_OK);
end;

How to build a filter string ?

As you can see in the above code, the filter string consists from the caption part and the filtering portion separated by the | char. You can also specify multiple filters by separating each filter string, again, by the | char, or you can specify multiple extensions for a single filter by separating extensions by ;.

So, e.g. to create a filter named JPG files filtering only *.jpg files you can write:

JPG files|*.jpg

To make two filters, let's say one for *.jpg files and one for *.jpeg files you can write:

JPG files|*.jpg|JPEG files|*.jpeg

And finally, to make a single filter for *.jpg and *.jpeg files you can write:

JPEG files|*.jpg;*.jpeg

For details I would refer you to the Delphi reference page for the TOpenDialog.Filter property.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to copy and rename files based on a txt file from directory and subdirectories

From Dev

How can I copy a directory and rename it in the same command?

From Dev

How can I reference a custom icon for a file association in Inno Setup?

From Dev

How can I reference a custom icon for a file association in Inno Setup?

From Dev

How can I copy files with duplicate filenames into one directory and retain both files by having the duplicate(s) rename automatically?

From Dev

How can I copy files with duplicate filenames into one directory and retain both files by having the duplicate(s) rename automatically in R?

From Dev

how can i copy file in data directory

From Dev

How can i copy image from drawable folder and paste into files directory in android?

From Dev

Inno Setup Copy Files and Folders to an Existing Zip File

From Dev

How can I recursively copy files by file extension, preserving directory structure?

From Dev

Can I rename files in a directory with Vim?

From Java

Inno Setup can't find image files using mask on AppVeyor

From Dev

How to rename the user file name at the Users directory?

From Dev

How can I monitor a directory for copy & pasting files?

From Dev

Why can I not rename the directory of my file?

From Dev

Inno Setup rename file if component selected

From Dev

Python copy files to a new directory and rename if file name already exists

From Dev

How can I use a SharePoint Site (365) as the source for Inno Setup files?

From Dev

How I can monitor new files in a directory and move/rename them into another directory?

From Dev

How can I copy a file from another directory to the current one?

From Dev

What should be done to copy files from installed directory to another after installation complete using inno setup script?

From Dev

How can I set the exit code from return code of my Execute File in Inno Setup?

From Dev

How can I use the FileSystemObject to "Copy and rename"

From Dev

Inno Setup: Use "Program Files" directory on both 32bit/64bit systems with {pf}

From Dev

How to copy and rename all files in a directory using Python?

From Java

How to catch the error message of bat file for deleting files in Inno Setup?

From Dev

How can I copy files and rename them according to their origin directories using Ruby?

From Dev

How can I automatically rename, copy and delete files in linux for my ip camera webcam?

From Dev

How can I recursively copy files by file extension?

Related Related

  1. 1

    How to copy and rename files based on a txt file from directory and subdirectories

  2. 2

    How can I copy a directory and rename it in the same command?

  3. 3

    How can I reference a custom icon for a file association in Inno Setup?

  4. 4

    How can I reference a custom icon for a file association in Inno Setup?

  5. 5

    How can I copy files with duplicate filenames into one directory and retain both files by having the duplicate(s) rename automatically?

  6. 6

    How can I copy files with duplicate filenames into one directory and retain both files by having the duplicate(s) rename automatically in R?

  7. 7

    how can i copy file in data directory

  8. 8

    How can i copy image from drawable folder and paste into files directory in android?

  9. 9

    Inno Setup Copy Files and Folders to an Existing Zip File

  10. 10

    How can I recursively copy files by file extension, preserving directory structure?

  11. 11

    Can I rename files in a directory with Vim?

  12. 12

    Inno Setup can't find image files using mask on AppVeyor

  13. 13

    How to rename the user file name at the Users directory?

  14. 14

    How can I monitor a directory for copy & pasting files?

  15. 15

    Why can I not rename the directory of my file?

  16. 16

    Inno Setup rename file if component selected

  17. 17

    Python copy files to a new directory and rename if file name already exists

  18. 18

    How can I use a SharePoint Site (365) as the source for Inno Setup files?

  19. 19

    How I can monitor new files in a directory and move/rename them into another directory?

  20. 20

    How can I copy a file from another directory to the current one?

  21. 21

    What should be done to copy files from installed directory to another after installation complete using inno setup script?

  22. 22

    How can I set the exit code from return code of my Execute File in Inno Setup?

  23. 23

    How can I use the FileSystemObject to "Copy and rename"

  24. 24

    Inno Setup: Use "Program Files" directory on both 32bit/64bit systems with {pf}

  25. 25

    How to copy and rename all files in a directory using Python?

  26. 26

    How to catch the error message of bat file for deleting files in Inno Setup?

  27. 27

    How can I copy files and rename them according to their origin directories using Ruby?

  28. 28

    How can I automatically rename, copy and delete files in linux for my ip camera webcam?

  29. 29

    How can I recursively copy files by file extension?

HotTag

Archive