Is this code trying to get the filename from the full path? I think ruby has a built-in way to do that: http://stackoverflow.com/a/374393/2883120