1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Tips: ファイルの作成日時をファイル名のソート順と同じ順序になるように変換するRubyスクリプト

Last updated at Posted at 2024-11-03

この記事は何

タイトルの通り、ディレクトリ内のファイルの作成日時をファイル名のソート順と同じ順序になるように変換するRubyスクリプトを作成したので記事として残しておきます。

スクリプト

以下の通りです。

require 'fileutils'

directory = '/path/to/directory'

files = Dir.glob(File.join(directory, '*')).sort

base_time = Time.now

files.each_with_index do |file, index|
  new_time = base_time + (index * 600) # 600 seconds = 10 minutes
  File.utime(new_time, new_time, file)
end

puts "Successfully updated creation dates for files in #{directory}"
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?