Module | FileUtils
In: | lib/standard/facets/fileutils/amass.rb lib/standard/facets/fileutils/cp_rx.rb lib/standard/facets/fileutils/ln_r.rb lib/standard/facets/fileutils/outofdate.rb lib/standard/facets/fileutils/safe_ln.rb lib/standard/facets/fileutils/slice.rb lib/standard/facets/fileutils/stage.rb lib/standard/facets/fileutils/wc.rb lib/standard/facets/fileutils/whereis.rb lib/standard/facets/fileutils/which.rb

### Methods

amass copy_entryx cp_rx head link_entry ln_r out_of_date? outofdate? safe_ln slice stage tail wc whereis which

### Classes and Modules

Module FileUtils::DryRun
Module FileUtils::NoWrite
Module FileUtils::Verbose

### Constants

OPT_TABLE | = | {} unless const_defined?(:OPT_TABLE)
LINKING_SUPPORTED | = | [true]
Win32Exts | = | %w{.exe .com .bat .cmd}
Win32Exts | = | %w{.exe .com .bat .cmd}

### External Aliases

uptodate? | -> | up_to_date?
| Alias for uptodate?

### Public Instance methods

amass(include_globs, exclude_globs=[], ignore=[])

An intergrated glob like method that take a set of include globs, exclude globs and ignore globs to produce a collection of paths.

The ignore_globs differ from exclude_globs in that they match by the basename of the path rather than the whole pathname.

TODO: Should ignore be based on any portion of the path, not just the basename?

copy_entryx(src, dest, filter, preserve = false, dereference_root = false, remove_destination = false)

Like FileUtils.copy_entry, but takes a filter proc that can return false to skip a file.

Note that if the filter rejects a subdirectory then everything within that subdirectory is automatically skipped as well.

cp_rx(src, dest, options = {}, &filter)

Like FileUtils.cp_r, but takes a filter proc that can return false to skip a file:

      cp_rx "bigDirectoryTree", "dest", {:noop => true} do |name|
         /dontCopyThis$/.match(name)
      end

Note that if the filter rejects a subdirectory then everything within that subdirectory is automatically skipped as well.

head(filename,lines) {|| ...}

In block form, yields the first number of `lines` of file `filename`. In non-block form, it returns an array of the first number of `lines`:

      # Returns first 10 lines of 'myfile'
      FileUtils.head("myfile", 10)

link_entry(src, dest, dereference_root = false, remove_destination = false)

Hard links a file system entry `src` to `dest`. If `src` is a directory, this method links its contents recursively.

Both of `src` and `dest` must be a path name. `src` must exist, `dest` must not exist.

If `dereference_root` is true, this method dereference tree root.

If `remove_destination` is true, this method removes each destination file before copy.

ln_r(src, dest, options = {})

Options: noop verbose dereference_root remove_destination

Hard link `src` to `dest`. If `src` is a directory, this method links all its contents recursively. If `dest` is a directory, links `src` to +dest/src+.

`src` can be a list of files.

      # Installing ruby library "mylib" under the site_ruby
      FileUtils.rm_r site_ruby + '/mylib', :force
      FileUtils.ln_r 'lib/', site_ruby + '/mylib'

      # Examples of copying several files to target directory.
      FileUtils.ln_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
      FileUtils.ln_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true

      # If you want to copy all contents of a directory instead of the
      # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
      # use following code.
      FileUtils.ln_r 'src/.', 'dest'     # cp_r('src', 'dest') makes src/dest,
                                         # but this doesn't.

TODO: Why —remove-destination and not just —force?

out_of_date?(path, *sources)

Alias for outofdate?

outofdate?(path, *sources)

The opposite of uptodate?

safe_ln(*args)

Attempt to do a normal file link, but fall back to a copy if the link fails.

CREDIT: Jim Weirich

slice(filename,from,to) {|| ...}

In block form, yields lines `from`-`to`. In non-block form, returns an array of lines `from`-`to`:

      # Returns lines 8-12 of 'myfile'
      FileUtils.body("myfile",8,12)

CREDIT Shashank Date, via Daniel Berger.

stage(stage_directory, source_directory, files, options={})

Stage by hard linking included files to a stage directory.

stage_directory - Where to stage the files source_directory - Where to find files to stage files - Files to link in stage relative to source

TODO: Rename to link_stage or something less likely to name clash? TODO: Add options for :verbose, :noop and :dryrun ?

tail(filename,lines)

In block form, yields the last number of `lines` of file `filename`. In non-block form, it returns the lines as an array.

Note that this method slurps the entire file, so I don‘t recommend it for very large files. If you want an advanced form of `tail`, I suggest using file-tail, by Florian Frank (available on the RAA):

      # Returns last 3 lines of 'myfile'
      FileUtils.tail("myfile",3)

And no tail -f.

wc(filename,option='all')

With no arguments, returns a four element array consisting of the number of bytes, characters, words and lines in filename, respectively.

Valid options are `bytes`, `characters` (or just ‘chars’), `words` and `lines`:

      # Return the number of words in 'myfile'
      FileUtils.wc("myfile",'words')

CREDIT: Daniel J. Berger

whereis(prog, path=ENV['PATH']) {|| ...}

In block form, yields each ((program)) within ((path)). In non-block form, returns an array of each ((program)) within ((path)). Returns (({nil})) if not found.

On the MS Windows platform, it looks for executables ending with .exe, .bat and .com, which you may optionally include in the program name:

       FileUtils.whereis("ruby")  #=> ['/usr/local/bin/ruby','/opt/bin/ruby']

CREDIT: Daniel J. Berger

which(prog, path=ENV['PATH'])

Looks for the first occurrence of program within path.

On the MS Windows platform, it looks for executables ending with .exe, .bat and .com, which you may optionally include in the program name. Returns `nil` if not found.

CREDIT: Daniel J. Berger, Michael Granger

[Validate]