Directory Utility





1
Date Submitted Sat. Feb. 18th, 2006 1:46 PM
Revision 3 of 3
Beginner seasons
Tags 0 | 1 | Ruby
Comments 2 comments
Directory Utility for Ruby


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

 

hata keisuke

hata.biz/
Hello!!

Comments

Comments Bug in subExt
Wed. Jul. 26th, 2006 6:56 PM    Newbie MyrddinE
  Comments Code blocks are good.
Wed. Jul. 26th, 2006 7:00 PM    Newbie MyrddinE

Voting

Votes Up


Syntax Master dannyboy
Scripter Sonsam

Votes Down


Scripter ASmith