Forum: Ruby Find.find or Dirwith spaces in filenames?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ezra Z. (Guest)
on 2006-01-27 22:05
(Received via mailing list)

	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
   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}..."
             convert(file, '')
	    puts "Converted to #{@scale}x#{@scale} #{file}..."
           @count_conv += 1
     @log_file << "\n\n#{@count_conv} logos were converted to
correctly sized gifs.\n\n\n"

	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-
This topic is locked and can not be replied to.