INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close