-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_mac_filenames.rb
46 lines (30 loc) · 943 Bytes
/
fix_mac_filenames.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Timelapse Maker
# 2015 Levi D. Smith
# Web: levidsmith.com
# Twitter: @GaTechGrad
# This is for date timestamp format for filename generated on the Mac
# This will update files with a space in the filename after the date
require 'fileutils'
filePath = "."
if (ARGV[0].nil? == false)
filePath = ARGV[0]
end
files = Dir.entries(filePath)
files.select! { | f |
puts "File: #{filePath}\\#{f}"
File.file? "#{filePath}\\#{f}"
}
files.select! { | f |
# f =~ /.*\.flv/
f =~ /.* .*\..*/
}
puts "Fixing #{files.size} filenames"
files.each { | f |
oldFileName = "#{f}"
puts "Old file: #{f}"
#Convert "YYYY-MM-DD hh-mm-ss.ext" to "YYYY-MM-DD-hhmm-ss.ext"
newFileName = "#{f[(0..9)]}-#{f[(11..12)]}#{f[(14..15)]}-#{f[(17..22)]}"
puts "New file: #{newFileName}"
puts "Moving: " + "#{filePath}\\#{oldFileName}" + " to " + "#{filePath}\\#{newFileName}"
FileUtils.mv("#{filePath}\\#{oldFileName}", "#{filePath}\\#{newFileName}")
}