こことここのリンクテキストに気付いたいくつかの異なるスクリプトを結び付けよ うとしています。ユーザーがディレクトリ文字とファイル拡張子を指定して、文字を削除したり、ファイルの名前を変更したりできる基本的なスクリプトを取得しようとしています。
全体を繋ぐのに苦労しています。これが私がこれまでのところです。
require 'fileutils'
define renamer(strip, stripdetails)
# So this is a strip function.
def strip(str,char)
new_str = ""
str.each_byte do |byte|
new_str << byte.chr unless byte.chr == char
end
new_str
end
# and then retrieve details from user.
#Get directory of files to be changed.
def stripdetails(strip myname)
puts "Enter Directory containing files"
STDOUT.flush
oldname = gets.chomp
puts "what characters do you want to remove"
str = gets.chomp
puts "what file extension do files end in?"
fileXt = gets.chomp
end
#And I found this from stackoverflow(I don't have enuff credits to post another hyperlink)
old_file = "oldname"
new_file = strip(oldname,str)
FileUtils.mv(old_file, new_file)