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
ezra@yakima-herald.com
Have a look at 'ri test' or 'ri File.directory?'.
HTH,
Guillaume.
···
On Tue, 2005-07-12 at 06:54 +0900, Ezra Zygmuntowicz wrote:
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
ezra@yakima-herald.com