sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    File class chokes on Norwegian Characters :(

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 815 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      I just discovered that if I have a folder with Norwegian characters (Γ¦ ΓΈ Γ₯ Γ† Ø Γ…) Ruby claims it doesn't exist.

      If you make a folder *C:\test_æøΓ₯* and then in the console File.exists?('C:\\test_æøΓ₯\\') it returns Error: #<Errno::ENOENT: No such file or directory
      If you remove the characters and then test - everything works.
      Any workarounds? (No, I can't ensure files/folders doesn't have the characters nor rename them. It'd cause havoc to our file at the office.)

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Strange... just after I published 'file_found?(path)' http://forums.sketchucation.com/viewtopic.php?p=168430#p168430
        My clunky method will work so long as only the tested file or topmost directory contains the accented characters... If anything down the path has them it fails...
        We can't split the path beyond a file/folder and it's container...
        file_found?("C:\test_æøΓ₯") true, but...
        file_found?("C:\test_æøΓ₯\myfile.txt") error- won't work unless you split it down and test for the file's container "C:\test_æøΓ₯\", but then you can't test for the file within the folder as it fails again...

        We need a fix for this - it must be possible...

        TIG

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          The File.exists? was only a sample. It also fails the methods that opens up a file.
          I came across this when I tried to use Rick's pageExIm plugin. When it tries to save the file it chokes.

          Fortunately the script isn't scrambled so I can patch it myself if I can find something that works.

          The script gets the model path from Sketchup.active_model.path and I wonder if this is the culprit where SU returns an UTF-8 String. Or some other encoding...

          I tried a dirty hack I found on the internet: fname.unpack("U*").map{|c|c.chr}.join without any better luck.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            The thing is though... I also get the error when typing in the string in the console. ... does the console go via SU that uses UTF-8 encoding?

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Don't understand why my hack doesn't work when I add it Rick's script...

              This works.

              @unknownuser said:

              fname = 'C:\test æøΓ₯\'

              C:\test æøΓ₯\

              File.exists?(fname)

              false

              fname

              C:\test æøΓ₯\

              fname.length

              15

              x=fname.unpack("U*").map{|c|c.chr}.join

              C:\test æøΓ₯\

              x.length

              12

              File.exists?(x)

              true

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                doh! I made a silly typo. The hack worked.
                Though - this hack only works while the characters can be translated to normal ASCII...

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  I'd say that model.path returning a UTF-8 string, when Ruby works with ASCII, is a bug. ? or not? Certainly needs a better solution though.

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    I've updated my file_found?(path) code here http://forums.sketchucation.com/viewtopic.php?p=169225#p169225 ...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement