Module FileUtils
In: lib/facet/fileutils/wc.rb
lib/facet/fileutils/tail.rb
lib/facet/fileutils/which.rb
lib/facet/fileutils/safe_ln.rb
lib/facet/fileutils/head.rb
lib/facet/fileutils/slice.rb
lib/facet/fileutils/whereis.rb

Methods

head   safe_ln   slice   tail   wc   whereis   which  

Constants

Win32Exts = %w{.exe .com .bat}
Win32Exts = %w{.exe .com .bat}

Public Class methods

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.

  require 'facet/fileutils/wc'

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

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

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.

Public Instance methods

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

  require 'facet/fileutils/head&tail'

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

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

In block form, yields lines ((from))-((to)). In non-block form, returns an array of lines ((from))-((to)).

  require 'facet/fileutils/head&tail'

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

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.

  require 'facet/fileutils/head&tail'

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

[Validate]