Skip to content

Instantly share code, notes, and snippets.

@ebot
Created June 25, 2012 17:28
Show Gist options
  • Save ebot/2990023 to your computer and use it in GitHub Desktop.
Save ebot/2990023 to your computer and use it in GitHub Desktop.
require 'fastercsv'
require 'fileutils'
require 'date'
docs = {}
rename = {}
FasterCSV.foreach( 'dupe_docs.txt', :headers => true, :col_sep => ';' ) do |row|
begin
fname = "#{row['OwnerFolderDate'].split(' ')[0]}_#{row['OwnerTypeName'].strip}_#{row['DocTypeName'].strip}_#{row['file_name']}"
folder = "#{DateTime.parse( row['OwnerFolderDate']).strftime('%Y')}-data"
file_path = File.join folder, fname
if File.exists? file_path
docs[row['DocId']] = file_path
else
rename[row['DocId']] = file_path
end
rescue Exception => e
puts e.message
end
end
# docs.each { |k, v| puts "#{k} => #{v}" }
rename.each do |k, v|
begin
FileUtils.cp docs[k], v
rescue Exception => e
puts "#{k} - #{e.message}"
end
end
require 'fastercsv'
require 'fileutils'
FasterCSV.foreach( 'index.txt', :headers => true, :col_sep => ';' ) do |row|
begin
FileUtils.mv row['file_name'],
"#{row['OwnerFolderDate'].split(' ')[0]}_#{row['OwnerTypeName'].strip}_#{row['DocTypeName'].strip}_#{row['file_name']}"
rescue Exception => e
puts e.message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment