私を判断せず、批判するだけにしてください! 実際、最近Rubyを習い始めたばかりか、これが私の最初のプログラムであるため、見つかったエラーはすべて有益です。 プログラムは、RMagickライブラリを使用してRubyで記述されています。 プログラムの仕組み:
1)ユーザーは、写真のあるディレクトリへのパスを入力します(jpg、png、gifは要素を展開します-(jpg | png | gif |その他の形式)
2)次に、写真の解像度に等しい名前のサブディレクトリが作成されるフォルダーへのパス。
3)次に、プログラムは、写真付きのディレクトリを再帰的に「実行」し、拡張子がjpg | png | gifのファイルを見つけ、解像度を決定し、名前に適切な解像度のディレクトリが存在するかどうかを確認します。
4)ファイルをコピーし、コピーされたファイルの数をカウントします。
Rubyコードは少しきれいに見えます-私の意見です。 ファイルを移動するのではなくコピーするプログラムでのみ、同様のRubyとPythonコードを比較することに興味がある人もいると思います。
まだ行われていないこと:コピーされたファイルの存在を確認し、存在する場合は名前を変更します。
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
Copy Source | Copy HTML require 'find' require 'fileutils' require 'RMagick' def image_sort (unsort_path, sort_path) count = 0 if ! File .directory?(sort_path) FileUtils .mkdir sort_path end if File .directory?(unsort_path) Find .find(unsort_path) { |fname| if /\.(jpg|png|gif)$/i =~ fname count += 1 img = Magick::Image::read(fname).first wh_dir_name = img.columns.to_s + 'x' + img.rows.to_s if ! File .directory?(sort_path + wh_dir_name) FileUtils .mkdir sort_path + wh_dir_name end FileUtils .cp(fname, sort_path + wh_dir_name) puts fname + ' copied' end } else puts unsort_path + ' not found' end puts count .to_s + ' file(s) copied' end puts 'Path to pictures: ' pd = gets pd. chomp ! puts 'Path to new sort directory: ' sd = gets sd. chomp ! image_sort ( pd, sd )
結果:
そのため、テスト用の写真のサイズが異なっていました。