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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-01-27 21:05
(Received via mailing list)
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
This topic is locked and can not be replied to.