How to use file filtering on folders.

asked 14 Sep '11, 08:07

Jake's gravatar image

Jake ♦♦
826222226235
accept rate: 98%


In the recently released InstallBuilder 6.2.5 a new filtering mechanism has been introduced for folders. This new functionality will allow you to pack the contents of a folder instead of including the folder itself and to apply filters to include or exclude scpecific files. For example, if we have a folder "documentation" and we want to pack a subset of its contents and unpack it to ${installdir}/myDocs, we just need to use the snippet below:

<folder>
   <description>Documentation Files</description>
   <destination>${installdir}/myDocs</destination>
   <name>documentation</name>
   <platforms>all</platforms>
   <distributionFileList>
       <distributionDirectory allowWildcards="1">
          <origin>/some/path/to/documentation/*</origin>
          <includeFiles>*/project-1-*.txt</includeFiles>
          <excludeFiles>*/project-1-secret.txt</excludeFiles>
       </distributionDirectory>
   </distributionFileList>
</folder>

In the above example, we have packed all of the .txt files related with "project-1" but not our secret "project-1-secret.txt"

Here are the new tags:

  • <allowWildcards> : This tag determines the behavior of the filtering mechanism. If it is set to "0" (the default), there won't be any global pattern interpretation and patterns will be taken as literal strings. For example, if we define <origin>/some/path/to/documentation/*</origin>, the installer will look for a folder named "*" inside the /some/path/to/documentation/ directory. In addition, the includeFiles and excludeFiles tags will be ignored. This will be equivalent to the old behavior.

However, if allowWildcards is set to "1", the <origin> will be expanded and the installer will generate a list of matching files.

  • <includeFiles> : This tag allows you to select files over the matches produced by the <origin> tag when wildcards are enabled. The default value of the <includeFiles> tag is "*" so all the files matched by the <origin> tag will be packed.

  • <excludeFiles> : Once the list of files has been filtered with the <includeFiles> pattern, the <excludefiles> filter will be applied over the result. The default value of this tag is empty so no filter is applied. This tag is ignored as well if wildcards are disabled.

The pattern interpretation in the <origin>, <includeFiles> and <excludeFiles> does not follow the same rules. The <origin> pattern is expanded over the existing files, like a "dir c:\Program Files\*txt" on Windows or "ls ~/*txt" on Unix. Forward and backwards slashes are normalized according to the platform. However, the patterns in the <includeFiles> and <excludeFiles> tags follow a stricter format:

  • Forward slashes are used as path separators, which let us escape special characters using backslashes. For example, to match .txt files, you must use /.txt files in both Windows and Unix systems.
  • The pattern is applied over the full path of the files and a string comparison is performed: <includeFiles>my.txt<includeFiles> won't work because it will compare "/some/path/to/my.txt" with "my.txt". */my.txt has to be used instead.
  • Multiple patterns can be included separated by ; or \n characters:

    <distributionDirectory allowWildcards="1"> <origin>/some/path/*</origin> <includeFiles>*/*.txt;*/*.jpg;*/*.bmp</includeFiles> <excludeFiles>*/*secret*.txt;*/myImage.bmp</excludeFiles> </distributionDirectory>

The special characters used in all the patterns are listed below:

  • ? : Matches any single character.
  • * : Matches any sequence of zero or more characters.
  • [chars] : Matches any single character in chars. If chars contains a sequence of the form a-b then any character between a and b (inclusive) will match.
  • {a,b,...} : Matches any of the strings a, b, etc.How to use file filtering on folders.
link

answered 14 Sep '11, 08:20

Jake's gravatar image

Jake ♦♦
826222226235
accept rate: 98%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×50
×25
×2

Asked: 14 Sep '11, 08:07

Seen: 1,620 times

Last updated: 14 Sep '11, 08:29