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

From: Ezra Zygmuntowicz [mailto:ezmobius@gmail.com]
Sent: Friday, January 27, 2006 1:03 PM
To: ruby-talk ML
Subject: Find.find or Dir[**/*] with spaces in filenames?

<snip>

  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

This looks ok to me. File.find yields files and directories with spaces
without any problem. Perhaps the problem is with the "convert"
function.

The easiest workaround (if that's the case) is to rename the file before
passing it to convert, replacing spaces with underscores.

Otherwise, you'll have to be more specific about the error you're
getting.

Regards,

Dan

···

-----Original Message-----

Daniel-

  Doh! Your of course correct. I wasn't looking in the right place to see what I was doing. This will let me finish what I need to do.

Thanks
-Ezra

···

On Jan 27, 2006, at 12:22 PM, Berger, Daniel wrote:

-----Original Message-----
From: Ezra Zygmuntowicz [mailto:ezmobius@gmail.com]
Sent: Friday, January 27, 2006 1:03 PM
To: ruby-talk ML
Subject: Find.find or Dir[**/*] with spaces in filenames?

<snip>

  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

This looks ok to me. File.find yields files and directories with spaces
without any problem. Perhaps the problem is with the "convert"
function.

The easiest workaround (if that's the case) is to rename the file before
passing it to convert, replacing spaces with underscores.

Otherwise, you'll have to be more specific about the error you're
getting.

Regards,

Dan