On Fri, 3 Feb 2006 13:42:11 -0800, Eric Hodel <drbrain@segment7.net>
wrote:
> If you don''t pass a nil value into Find::find you won''t
have
> this error.
>
> What is the full backtrace including a small script to
> illustrate the problem.
I do not know what I was doing wrong to begin with, but the problem
has disappeared (for now).
I am trying to discover how, exactly, to use FindTest. with
Find.prune so that I can list all of the regular files in a single
directory but not recurse lower directories. I seem to be able to
either list every file in every directory under the specified root,
or none at all.
This will eventually form part of a mini-rails application that
will (when finished) take a set of three csv files passed from an
HP3000 via FTP (file names limited to 8 characters, all uppercase),
munge them to lowercase, add a .csv extension, and move them out of
the incoming directory to the data depository where the rails
application (yet to be written) will eventually (I hope and pray)
dynamically parse them for client display via an https link.
This is a requirement that has just cropped up. As we are in the
process of designing in Rails the replacement system for the HP3000
based application it seemed appropriate to do this particular task
in Ruby as a learning exercise and as a management demonstration
(quickly in other words).
The current test script is listed below. Please allow for line
wrapping. It does not try and do anything yet, just displays where
it is, what it is looking at, and how it would treat whatever that
is.
Regards,
Jim
###
#!/usr/bin/env ruby
#--
# This line will not be copied into an rdoc document.
# Those after the next tag will.
#++
# bulkren.rb - Bulk Rename of all files that meet selection #
criteria.
# 2006 Feb 03 - Byrne, James B. - JBB8 -
#
# If environment variable RENPATH is set and is a valid path then
# files on that directory will be targeted. If not set then a
# default value will be provided (./)
#
# ToDo: TOO MUCH
#
#--
require ''fileutils''
require ''find''
# Test for external environment variable and default to pwd if not.
fpath = ENV["RENPATH"] ? ENV["RENPATH"].to_s :
"./"
if !FileTest.directory?(fpath) then
puts "RENPATH enviroment variable set and ''" +
ENV["RENPATH"].to_s + "''"
puts "is not a valid directory."
Process.exit
end
Find.find(fpath) do |filename|
if FileTest.file?(filename)
puts filename
puts FileTest.readable?(filename) ? "\treadable" : "\tnot
readable"
puts FileTest.writable?(filename) ? "\twritable" : "\tnot
writable"
# ToDo here:
# 1. Check permissions on file.
# 2. File.rename oldfile to same with .csv extension
next
else
if FileTest.directory?(filename)
puts filename + " is a directory."
if File.basename(filename)!= ?.
puts File.basename(filename) + " is something"
Find.prune
else
next
end
end
end
end
puts "End bulkren.rb"
--
*** e-mail is not a secure channel ***
mailto:byrnejb.<token>@harte-lyne.ca
James B. Byrne Harte & Lyne Limited
vox: +1 905 561 1241 9 Brockley Drive
fax: +1 905 561 0757 Hamilton, Ontario
<token> = hal Canada L8E 3C3