Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | File | rename

概要

File.rename

詳細

ファイル名を変更する

サンプル

コード
# encoding: utf-8

def create_file(filename, contents)
  File.open(filename, 'w:utf-8') {|f|f.print contents}
end

create_file 'old_hoge.txt', "test"
system('ls *.txt')
File.rename 'old_hoge.txt', "new_hoge.txt"
system('ls *.txt')
出力
old_hoge.txt
new_hoge.txt