Method: Path#rename
- Defined in:
- lib/epitools/path.rb
#rename(arg) ⇒ Object Also known as: ren, rename_to
Renames the file, but doesn’t change the current Path object, and returns a Path that points at the new filename.
Examples:
Path["file"].rename("newfile") #=> Path["newfile"]
Path["SongySong.mp3"].rename(:basename=>"Songy Song")
Path["Songy Song.mp3"].rename(:ext=>"aac")
Path["Songy Song.aac"].rename(:dir=>"/music2")
Path["/music2/Songy Song.aac"].exists? #=> true
1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/epitools/path.rb', line 1030 def rename(arg) dest = arg_to_path(arg) raise "Error: destination (#{dest.inspect}) already exists" if dest.exists? raise "Error: can't rename #{self.inspect} because source location doesn't exist." unless exists? File.rename(path, dest) dest end |