Find.find or Dir[**/*] with spaces in filenames?

E

Ezra Zygmuntowicz

Friends-

I have a bunch of automation built using ruby and highline(thanks
James and Greg!!!) set up for processing text and image files for the
classified and obituaries at the newspaper I work for. But I am
trying to make these processes as stable as possible and I am running
into issues with image names with spaces in them.

We have instated a policy that states logos or obit images can only
be named with lowercase letters, underscores and numbers and no
spaces. but inevitably, images sneak through the system with spaces
in the names. I am grabbing these images from a directory structure
recursively and resizing and converting them with imagemagick which
works great. But when there is an image with spaces in the name it
breaks my scripts.

Here is a small example of what I am doing. Is there a way to
properly quote file or directory names with spaces in them using
Find.find or Dir[**/(] to recurse through a dir tree and grab
appropriate files?


#This is part of a larger class so its just an example of the dir
recursing.
def process(dir)
@count_conv = 0
print "converting..."
Find.find(dir) do |file|
if file =~ /\.eps$/
@log_file << file + "\n"
unless test(?d, file)
if too_big?(file)
convert(file, "-resize #{@scale}x#{@scale}")
puts "Converted to #{@scale}x#{@scale} #{file}..."
else
convert(file, '')
puts "Converted to #{@scale}x#{@scale} #{file}..."
end
@count_conv += 1
end
end
end
@log_file << "\n\n#{@count_conv} logos were converted to
correctly sized gifs.\n\n\n"
end

So is there another library or option I am missing that will allow
something like this to work with directories or files with spaces in
the names? I would like to be able to do a sub on the names to
replace spaces with underscores.

Thanks in advanced-
-Ezra
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top