Last active 1742947713

test.rb Raw
1require 'fileutils'
2
3# Set the directory path
4dir_path = "./cleanup-tiff-posts/"
5
6# Define a regex to match common date formats in filenames
7date_pattern = /(\d{4}-\d{2}-\d{2})|(\d{2}-\d{2}-\d{4})/
8
9# Loop through each file in the directory
10Dir.foreach(dir_path) do |filename|
11 next if filename == '.' || filename == '..'
12
13 new_filename = filename.gsub(date_pattern, '').gsub('__', '_').strip
14 new_path = File.join(dir_path, new_filename)
15
16 # Rename the file if the name has changed
17 if new_filename != filename
18 FileUtils.mv(File.join(dir_path, filename), new_path)
19 puts "Renamed: #{filename} -> #{new_filename}"
20 end
21end
22
23puts "Date removal complete!"