Module | FileUtils
In: | lib/facets/core/fileutils/split_all.rb lib/facets/core/fileutils/slice.rb lib/facets/core/fileutils/which.rb lib/facets/core/fileutils/stage.rb lib/facets/core/fileutils/whereis.rb lib/facets/core/fileutils/safe_ln.rb lib/facets/core/fileutils/wc.rb lib/facets/core/fileutils/compress.rb

Extentions to FileUtils adding compression methods.

### Methods

compress head safe_ln slice split_all tail tar_bz2 tar_bzip tar_gz tar_gzip untar_bz2 untar_bzip untar_gz untar_gzip unzip wc whereis which zip

### Included Modules

Stage

### Classes and Modules

Module FileUtils::DryRun
Module FileUtils::Stage

### Constants

Win32Exts | = | %w{.exe .com .bat}
Win32Exts | = | %w{.exe .com .bat}
LINKING_SUPPORTED | = | [true]
COMPRESS_FORMAT | = | { 'tar.gz' => 'tar_gzip', 'tgz' => 'tar_gzip', 'tar.bz2' => 'tar_bzip', 'zip' => 'zip', '.tar.gz' => 'tar_gzip', '.tgz' => 'tar_gzip', '.tar.bz2' => 'tar_bzip', '.zip' => 'zip'

### Public Instance methods

compress( format_extension, folder, to_file=nil )

Compress based on given extension. Supported extensions are:

- tar.gz
- tgz
- tar.bz2
- zip

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

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")

safe_ln(*args)

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

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)

split_all(path)

Splits a file path into an array of individual path components. This differs from `File.split`, which divides the path into only two parts, directory path and basename.

      split_all("a/b/c") =>  ['a', 'b', 'c']

tail(filename,lines=10)

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). And no tail -f.

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

tar_bz2( folder, to_file=nil )

Alias for tar_bzip

tar_bzip( folder, to_file=nil )

Tar Bzip2

tar_gz( folder, to_file=nil )

Alias for tar_gzip

tar_gzip( folder, to_file=nil )

Tar Gzip

untar_bz2( file )

Alias for untar_bzip

untar_bzip( file )

Untar Bzip2

untar_gz( file )

Alias for untar_gzip

untar_gzip( file )

Untar Gzip

unzip( file )

Unzip

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')

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.

       File.whereis("ruby") -> ['/usr/local/bin/ruby','/opt/bin/ruby']

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.

zip( folder, to_file=nil )

Zip

[Validate]