I have the following code which reads each line of a csv and cleans up each row. The rows are all path\ file name directories. I am having an issue where the script cannot find a path\file because the file name has a - in it. The - (dash) is read by ruby as \x96 . Does anyone know how to get it to not do that, and to read the - as a dash?
This is what I have, but it is not working:
A possible line is M:\path1\Path 2\Path3\File – name.doc To make this more difficult, I found the - is not a simple dash. Its an extended dash. That is why it's having the problem.
I need it to read the file path as is. I tried encode and it removes that dash in ruby. If I can't get ruby to read the file and path that exists, it won't find the file. I can't change the file name. It has to be what it is.
I've been looking it up for hours!
Any help would be greatly appreciated.
misscrf
It is never too late to become what you could have been ~ George Eliot
This is what I have, but it is not working:
Code:
CSV.foreach("#{batch_File_Dir_sdata}") do |ln|
line_number += 1
pathline = ln.to_s
log_linemsg = "Source #{line_number}= #{pathline}"
log_line = ["#{$cname}","#{log_linemsg}","","",]
puts log_linemsg
insert_logitems(connection, table_namelog, log_line)
if pathline.include?("\\")
cleanpath = pathline.gsub!("\\\\","\\")
#cleanpath = cleanpath.gsub!("[","")
#cleanpath = cleanpath.gsub!("]","")
cleanpath.gsub!("\"","")
#THIS IS THE LINE WHERE I AM TRYING TO FIX THE ISSUE
cleanpath.gsub!("\\x96","\-")
cleanpath.slice!(0)
cleanpath.chop!
#puts "Clean path - has backslash\n#{cleanpath}"
else
cleanpath = pathline
#puts "#{cleanpath}"
#puts "Clean path - has NO backslash\n#{cleanpath}"
end
I need it to read the file path as is. I tried encode and it removes that dash in ruby. If I can't get ruby to read the file and path that exists, it won't find the file. I can't change the file name. It has to be what it is.
I've been looking it up for hours!
Any help would be greatly appreciated.
misscrf
It is never too late to become what you could have been ~ George Eliot