Directory Utility
class Dir
def Dir.escape(path)
path_new = []
path.unpack("C*").map{ |n|
# meta char
if( %q{"$&'()*/;<>?[\\`|}.include?(n) )
path_new.push(0x5C)
path_new.push(n)
else
path_new.push(n)
end
}
path_new.pack("C*")
end
# get ext
def Dir.getExt( fullpath )
len = fullpath.rindex('.')
return "." if len==nil
fullpath[ len , fullpath.length-len ]
end
# change ext
def Dir.subExt( filename , newext )
return if filename.rindex('.')==nil
newext = ('.'+newext) if newext[0]!='.'
filename.sub!( /\..+/,newext )
end
end






Hello!!
It will get improperly modified by subExt(), to Foo.new
The gsub line should be /\.[^.]+/ rather than /\..+/. The extension itself should not contain any periods.
Also, there is nothing wrong with adding a newext onto a file with no extension... for example, subExt("My File", "txt") should return "My File.txt".
# change ext
def Dir.subExt( filename , newext )
newext = ('.'+newext) if newext[0] != '.'
if filename.rindex('.')
filename.sub!( /\.[^.]+/,newext )
else
filename << newext
end
end