How to tell Dir from file?

E

Ezra Zygmuntowicz

Hello list-
I have the following script that recursively descends through
some directories and changes the name of a bunch of logos to be
webserver compliant.

require 'find'
require 'ftools'
path = "/Volumes/Users/ez/LOGOS/"

def rename(filename)
new_name = File.join(File.dirname(filename), fix_name(File.basename
(filename)))
File.move(filename, new_name)
end

def fix_name(name)
name.gsub!(/[\s_]/, "-")
name.downcase!
name.gsub!(/[^a-z0-9.-]*/, '')
end

Find.find(path) do |file|
rename(file)
end

I need to know how to tell the difference between a file with no
extension and a directory name. The script works perfectly right now
except when it first runs into a directory it makes a 0 byte file
with the same name within that directory. I need to know how to test
whether the current iteration contains an actual file or is a
directory so I can skip renaming it.

You help is much appreciated.


-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
509-577-7732
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
Best cryptoconsultant

Latest Threads

Top