- 233 名前:デフォルトの名無しさん mailto:sage [2020/05/08(金) 12:22:27 ID:Fn4yfVbS.net]
- >>221
Ruby で作った。 DryRun なので、実際には実行されません require 'fileutils' dest_dir = "C:/test2" keyword = "hoge[hoge]" # 絶対パスのディレクトリ名の後ろに、* を付けること! # . で始まる、隠し directory, file を除く glob_pattern = "C:/test/*" src_dir = File.dirname( glob_pattern ) # ディレクトリパスだけを取り出す Dir.glob( glob_pattern ) .select { |full_path| File.file?( full_path ) } # ファイルのみ .select { |full_path| File.basename( full_path, ".*" ) === keyword } # 拡張子を取り除いた部分のファイル名 .each do |full_path| dest_path = dest_dir + "/" + File.basename( full_path ) # ファイル名 FileUtils::DryRun.move( full_path, dest_path ) end 出力 mv C:/test/hoge[hoge].txt C:/test2/hoge[hoge].txt
|

|