#!/usr/bin/env ruby
# =============================================================================
# Create
# name : Andre Rikkert de Koe date: Apr 2011
# descr : filefind
# This is a demo of programming in the ruby language.
# Its part of a project to implement a program to create a directory
# tree similar to the output of the Unix find program.
# EUID : Any user who has read access to all the files being searched for.
# run : interactive
#
# Changes
# name : date:
# descr : short description
#
# =============================================================================
# =============================================================================
# Functions
# =============================================================================
def Usage(progname, mesg)
puts "Usage: #{progname} directory"
puts mesg
end
#
# dir is directory to traverse
#
def traverse(dir)
curdir = Dir.getwd
Dir.chdir(dir)
curdir2 = Dir.getwd
Dir.foreach(Dir.getwd) { | file |
pfile = curdir2 + "/" +file
if File.directory?(file) && !File.symlink?(file)
if (file != "..") && (file != ".")
puts pfile
traverse(file)
end
else
if File.file?(file) || File.symlink?(file)
puts "#{pfile}"
else
puts "WARNING: Could not process file $pfile"
end
end
}
Dir.chdir(curdir)
end
def start_traverse(directory)
puts directory
traverse(directory)
end
# =============================================================================
# MAIN
# =============================================================================
progname = File.basename($0)
if (ARGV.length == 1)
directory = ARGV[0]
if File.directory?(directory)
start_traverse(directory)
else
Usage progname, "ERROR: Not a directory #{directory}"
end
else
Usage progname, "ERROR: 1 argument expected"
end