Sys.glob                package:base                R Documentation

Wildcard Expansion on File Paths

Description:

     Function to do wildcard expansion (also known as 'globbing') on
     file paths.

     Not all platforms support this.

Usage:

     Sys.glob(paths, dirmark = FALSE)

Arguments:

   paths: character vector of patterns for relative or absolute
          filepaths.  Missing values will be ignored.

 dirmark: logical: should matches to directories from patterns that do
          not already end in '/' have a slash appended?  May not be
          supported on all platforms.

Details:

     This expands wildcards in file paths.  For precise details, see
     your system's documentation on the 'glob' system call.  There is a
     POSIX 1003.2 standard (see <URL:
     http://www.opengroup.org/onlinepubs/009695399/functions/glob.html>)
     but some OSes will go beyond this (in particular some BSD-based
     OSes also do tilde expansion, see 'path.expand').

     All systems should interpret '*' (match zero or more characters),
     '?' (match a single character) and '[' (begin a character class or
     range).  If a filename starts with '.' this must be matched
     explicitly.  By default paths ending in '/' will be accepted and
     matched only to directories.

     The rest of these details are indicative (and based on the POSIX
     standard).

     '[' begins a character class.  If the first character in '[...]'
     is not '!', this is a character class which matches a single
     character against any of the characters specified.  The class
     cannot be empty, so ']' can be included provided it is first.  If
     the first character is '!', the character class matches a single
     character which is _none_ of the specified characters.

     Character classes can include ranges such as '[A-Z]': include '-'
     as a character by having it first or last in a class.  (The
     interpretation of ranges should be locale-specific, so the example
     is not a good idea in an Estonian locale.)

     One can remove the special meaning of '?', '*'  and '[' by
     preceding them by a backslash (except within a character class).

Value:

     A character vector of matched file paths.  The order is
     system-specific (but in the order of the elements of 'paths'): it
     is normally collated in either the current locale or in byte
     (ASCII) order.

     Directory errors are normally ignored, so the matches are to
     accessible file paths (but not necessarily accessible files).

     On platforms which do not have the 'glob' system call (nor, as for
     R under Windows, an emulation), 'paths' is returned unchanged.

See Also:

     'path.expand'.

     Quotes for handling backslashes in character strings.

Examples:

     ## Not run: 
     Sys.glob(file.path(R.home(), "library", "*", "R", "*.rdx"))
     ## End(Not run)

