tiffmin revised this gist . Go to revision
1 file changed, 23 insertions
test.rb(file created)
@@ -0,0 +1,23 @@ | |||
1 | + | require 'fileutils' | |
2 | + | ||
3 | + | # Set the directory path | |
4 | + | dir_path = "./cleanup-tiff-posts/" | |
5 | + | ||
6 | + | # Define a regex to match common date formats in filenames | |
7 | + | date_pattern = /(\d{4}-\d{2}-\d{2})|(\d{2}-\d{2}-\d{4})/ | |
8 | + | ||
9 | + | # Loop through each file in the directory | |
10 | + | Dir.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 | |
21 | + | end | |
22 | + | ||
23 | + | puts "Date removal complete!" |
Newer
Older