Directory Utility





1
Date Submitted Sat. Feb. 18th, 2006 12:02 PM
Revision 1 of 3
Beginner seasons
Tags 0 | 1 | Ruby
Comments 2 comments
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) #=>
# â€šÂ»â€šÃªË ÃˆÅ O
else
path_new.push(n)
end
}
path_new.pack("C*")
end

# getext
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
Directory Utilitys

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