He trabajado hasta el siguiente Ruby script para copiar los atributos de fecha antigua para cada archivo y carpeta a la ruta de destino coincidentes archivos y carpetas:
(Guardado como ~/bin/copy_dates.rb
; nano ~/bin/copy_dates.rb
y pegar)
#!/usr/bin/env ruby
# We require the "find" and "fileutils" libraries to work with files and directories
require 'find'
require 'fileutils'
# Retrieve the source and destination root directories from the command line arguments
src_root = ARGV[0]
dst_root = ARGV[1]
# Count the total number of files in the source root directory
total_files = Dir[File.join(src_root, '**', '*')].count { |file| File.file?(file) }
# Initialize a counter for the current file being processed
current_file = 0
# Traverse through all the files in the source root directory
Find.find(src_root) do |src|
# Replace the source root path with the destination root path to create the destination file path
dst = src.sub(/^#{Regexp.escape(src_root)}/, dst_root)
# Check if the source file exists - for both folders and files:
if File.exist?(src)
begin
# Retrieve the access time (atime) and modification time (mtime) of the source file
src_atime = File.atime(src)
src_mtime = File.mtime(src)
# Use the `stat` command to retrieve the birth or creation time (btime) of the source file
src_btime = `/usr/bin/stat -f "%SB" -t "%m/%d/%Y %H:%M:%S" "#{src}"`.chomp
# Retrieve the access time (atime), modification time (mtime), and birth time (btime) of the destination file
dst_atime = File.atime(dst)
dst_mtime = File.mtime(dst)
dst_btime = `/usr/bin/stat -f "%SB" -t "%m/%d/%Y %H:%M:%S" "#{dst}"`.chomp
# Check if the source and destination file timestamps match
if src_atime == dst_atime && src_mtime == dst_mtime && src_btime == dst_btime
puts "[#{current_file}/#{total_files}] #{src}: Skipped - timestamps match"
else
# If the timestamps don't match, update the access time and modification time of the destination file
File.utime(src_atime, src_mtime, dst)
# Use the `SetFile` command to update the birth time of the destination file
system("SetFile -d '#{src_btime}' '#{dst}'")
puts "[#{current_file}/#{total_files}] #{src}: Updated - timestamps copied"
end
# If an error occurs while processing a file, catch the exception and print an error message
rescue Exception => e
puts "Error processing #{src}: #{e}"
end
end
# Increment the current file counter
current_file += 1
end
Recuerde hacer el archivo ejecutable y llamarlo como en el siguiente ejemplo:
chmod +x ~/bin/copy_dates.rb
copy_dates.rb /source/path/to/folder /destination/path/to/folder