Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a long dash in a csv for folder file directory?

Status
Not open for further replies.

misscrf

Technical User
Jun 7, 2004
1,344
0
0
US
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:
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
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top