Last active
August 29, 2015 14:05
-
-
Save motoishmz/3be6b31318be68ba0c28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "FileUtils" | |
# 検索結果保存用 | |
matches = [] | |
# ここでフィルター条件をdefine | |
def filter(filename) | |
# 拡張子を取る | |
base_name = File::basename(filename, ".*") | |
# 数字に変換 (名前を to integer する) | |
file_num = base_name.to_i | |
# 6の倍数ならtrue | |
return (file_num % 6 == 0) | |
end | |
# このruby fileと同じdirのファイルに対して一括操作 | |
Dir::entries(".").each{ |frame| | |
abs_path = File::expand_path(frame) | |
next if File.ftype(abs_path) != "file" | |
next if File.basename(abs_path) =~ /^\./ | |
next if File.basename(abs_path) =~ /\.rb$/ | |
# 条件に合ってたら、matchesの中にファイル名を保存 | |
if filter(frame) then | |
matches.push( abs_path ) | |
end | |
} | |
# ./copied フォルダの中を空に | |
save_folder_path = "./copied" | |
FileUtils.rm(Dir.glob(save_folder_path+'/*.*')) | |
FileUtils.mkdir_p(save_folder_path) | |
# matchした全ファイルをコピー | |
matches.each{ |src| | |
dest = save_folder_path + "/" + File::basename(src) | |
FileUtils.cp( src, dest ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment