@martinrinehart said:
@dan rathbun said:
What's wrong with the standard included classes File and Dir ??
You can do all that would be desired with their methods.
That's all I've done:
def cd( path ) Dir::chdir( path ) end
Shell Commands are already allowed within Ruby. [Examples for PC win32 platform, but also applies to Mac OSX.]
use the %x delimiter, as in: %x{dir *.skp}
or backquoted strings, as in: dir *.skp
(from: Programming Ruby -
The Pragmatic Programmer's Guide)
The Ruby Language > Expressions > Single Terms
Shell Command. A shell command is a string enclosed in backquotes, or in a general delimited string (page 200) starting with %x. The value of the string is the standard output of running the command represented by the string under the host operating system's standard shell. The execution also sets the $? variable with the command's exit status.
[Example - '.c' changed to '.skp';'ls' changed to 'dir'.]
%(#BF0000)[filter = "*.skp"
files = dir #{filter}
files = %x{dir #{filter}}]
! Backquoted strings allow replacement like doublequoted strings !
Expressions > Miscellaneous Expressions**http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html**
Command Expansion
If you enclose a string in backquotes, or use the delimited form prefixed by %x, it will (by default) be executed as a command by your underlying operating system. The value of the expression is the standard output of that command.
! The output is a String, so any String method can be applied to the expression: Ex:
dir.include?('.jpg')
returns true if there are any jpeg files in the dir
_