Created
June 25, 2012 17:28
-
-
Save ebot/2990023 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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