module RIO::IF::Dir
Public Instance Methods
Calls ::Dir#chdir.
Changes the current working directory of the process to the directory specified by the Rio
. Raises a SystemCallError (probably Errno::ENOENT) if the target directory does not exist or if the Rio
does not reference a directory.
If a block is given changes to the directory specified by the rio for the length of the block and changes back outside the block
Returns the Rio
rio('/home').chdir # change the current working directory to /home # the working directory here is /home rio('/tmp/data/mydata').delete!.mkpath.chdir { # the working directory here is /tmp/data/mydata } # the working directory here is /home
# File lib/rio/if/dir.rb, line 45 def chdir(&block) target.chdir(&block);self end
Calls Find#find
Uses ::Find#find to find all entries recursively for a Rio
that specifies a directory. Note that there are other ways to recurse through a directory structure using a Rio
. See #each and #all.
Calls the block passing a Rio
for each entry found. The Rio
inherits file attrubutes from the directory Rio
.
Returns itself
rio('adir').find { |entrio| puts "#{entrio}: #{entrio.file?}" } rio('adir').chomp.find do |entrio| next unless entrio.file? lines = entrio[0..10] # lines are chomped because 'chomp' was inherited end
# File lib/rio/if/dir.rb, line 67 def find(*args,&block) target.find_entries(*args,&block); self end
Calls ::Dir#glob
Returns the filenames found by expanding the pattern given in string, either as an array or as parameters to the block. In both cases the filenames are expressed as a Rio
. Note that this pattern is not a regexp (it�s closer to a shell glob). See File::fnmatch for details of file name matching and the meaning of the flags parameter.
# File lib/rio/if/dir.rb, line 79 def glob(string,*args,&block) target.glob(string,*args,&block) end
Calls FileUtils#mkdir
Makes a new directory named by the Rio
with permissions specified by the optional parameter. The permissions may be modified by the value of File::umask
Returns the Rio
. If the directory already exists, just returns the Rio
.
rio('adir').mkdir
# File lib/rio/if/dir.rb, line 132 def mkdir(*args,&block) target.mkdir(*args,&block); self end
Calls ::Dir#rmdir
Deletes the directory referenced by the Rio
. Raises a subclass of SystemCallError if the directory isn�t empty. Returns the Rio
. If the directory does not exist, just returns the Rio
.
See also rmtree
, #delete, #delete!
rio('adir').rmdir # remove the empty directory 'adir'
# File lib/rio/if/dir.rb, line 92 def rmdir() target.rmdir(); self end
Calls FileUtils#rmtree
Removes a directory Rio
recursively. Returns the Rio
. If the directory does not exist, simply returns the Rio
If called with a block, behaves as if rmtree.each(&block)
had been called
See also #delete!
rio('adir').rmtree # removes the directory 'adir' recursively # delete the directory 'adir', recreate it and then change to the new directory rio('adir/asubdir').rmtree.mkpath.chdir { ... }
# File lib/rio/if/dir.rb, line 112 def rmtree() target.rmtree(); self end