This is an old revision of the document!

Masks

To use the following features of WinSCP you need to specify a mask (wildcard) to select files (or other things):

Advertisement

You can use File Mask dialog to help you with assembling the mask.

Basic Syntax

When specifying the mask you can use following patterns:

Pattern Meaning Example
* Matches any number (including zero) of arbitrary characters. *.doc; about*.html
? Matches exactly one arbitrary character. photo????.jpg
[abc] Matches one character from the set. index_[abc].html
[a-z] Matches one character from the range. index_[a-z].html

All other characters are treated literally (except for special characters used in the constructs described below).

Advertisement

To escape character with special meaning in patterns (*?[) surround it by set pattern, e.g. filewithstar[*].

sadsad

Combining Masks

In most contexts, you can combine several masks using semicolon (;) or comma (,). You cannot use this in source parameters of script commands and .NET assembly methods.1

For example following mask includes all JPG and GIF images: *.jpg; *.gif.

To escape separator character double it, e.g. filewith,,comma.

Include and Exclude Masks

Mask can combine include and exclude mask separated by pipe (|). You cannot use this in source parameters of script commands and .NET assembly methods.1

For example following mask includes all JPG and GIF images, but excludes those starting with 2010 and 2011: *.jpg; *.gif | 2010*; 2011*.

Both include and exclude part can be empty, denoting that everything is included or nothing is excluded, respectively. When include part is empty, masks starts with pipe straight away. When exclude part is empty, you can omit the trailing pipe.

Exclude mask takes precedence over include mask. I.e. when the same file is matched by both the exclude and include mask, it is excluded.

To escape pipe character double it, e.g. filewith||pipe.

Directory Mask

To use the mask for directories, append a slash to the end, e.g. images/. The mask */ matches any directory.

Note that when using File Mask dialog, the trailing slash for directory masks is appended automatically.

To make operation non-recursive use exclude mask */.2

Directory masks are recursive. E.g. mask images/ matches directories /home/martin/images/ as well as /home/martin/images/avatars/.

Path Mask

When a mask selects files and it makes sense to select them based on directory, you can extend the mask with a path mask. You should separate the path mask from the filename mask by a slash. For example mask /home/martinp/*.txt matches all text files within the directory. To match all text files within subtree, use mask /home/martinp/*.txt; /home/martinp/*/*.txt.3

The path mask is matched against full path, i.e. not against path relative path to a root of file transfer or synchronization. E.g. mask public_html/wiki/ does not match /home/martinp/public_html/wiki directory, even if the root of file transfer or synchronization is /home/martinp. Partial path mask that matches an absolute path may look like */public_html/wiki/.

Advertisement

For a partial path mask it makes no difference whether you use back (\) or forward slashes (/); the mask will always work for both local and remote paths. For example, a mask */public_html/*.bak will match backup files both in D:\Documents\public_html\ and /home/martinp/public_html/.

You can also specify full path to a specific file or directory, both local and remote. For example if you want to match only a specific .csv directory, not all, use /home/martinp/data/.csv/ instead of .csv/.

The full path mask matches a local or a remote paths only, depending on the syntax used.4 This matters for synchronization particularly. For exclude masks, may need to use a separate full path mask for both local and remote path. For include masks, using a full path mask does not make sense with synchronization, as is effectively excludes all files on the other side of the synchronization, breaking it. In general, use partial path masks with the synchronization.

Exceptions

For convenience, mask *.* is an exception matching any file or directory, even if its name does not include any dot. On the contrary, mask *. matches any file or directory without an extension.

  1. Note that this restriction does not apply to -filemask switch in scripting and TransferOptions.FileMask in .NET assembly.Back
  2. Full inline file mask syntax, in case there’s no other mask involved, is |*/, where the | denotes a start of an exclude mask.Back
  3. Simpler, but less precise, form would be /home/martinp*/*.txt.Back
  4. Paths starting with drive letter and colon match local paths only. Paths starting with slash match remote path only. Type of slashes does not matter.Back

Last modified: by 203.188.238.29