# Find.find or Dirwith spaces in filenames?

**URL:** <https://www.ruby-forum.com/t/find-find-or-dirwith-spaces-in-filenames/98056>\
**Category:** Ruby\
**Created:** [January 27, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/find-find-or-dirwith-spaces-in-filenames/98056 "2006-01-27T21:05:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezra\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f07891/32.png) [@ezra\_z](https://www.ruby-forum.com/u/ezra_z)\
**Post date:** [January 27, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/find-find-or-dirwith-spaces-in-filenames/98056/1 "2006-01-27T21:05:12Z")

</div>

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
