【.cmd】 バッチファイルスクリプト %13 【.bat】at TECH
【.cmd】 バッチファイルスクリプト %13 【.bat】 - 暇つぶし2ch755:デフォルトの名無しさん
20/04/21 22:46:58.98 HADG6GDb.net
>>721
Ruby で作った。
ただし、DryRun なので実際には実行されません。
001.txt, 002.txt に変わります
require 'fileutils'
# 絶対パスのディレクトリ名の後ろに、* を付けること!
# . で始まる、隠し directory, file を除く
dir_path = "C:/Users/Owner/test/*"
target_dir = File.dirname( dir_path ) # ディレクトリパスだけを取り出す
Dir.glob( dir_path )
.select { |full_path| File.file?( full_path ) } # ファイルのみ
.each.with_index( 1 ) do |full_path, idx| # index は、1 から始まる
# format で、0埋め3桁表示にする。extname は拡張子
# ファイル名は、001.txt, 002.txt など
dest_path = target_dir + "/" + ( "%03d" % idx ) + File.extname( full_path )
FileUtils::DryRun.move( full_path, dest_path )
end


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch