sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Getting user home directory

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 245 Views 3 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.
    • D Offline
      draftomatic
      last edited by

      As I google for a solution it seems that people use either ENV['HOME'] or File.expand_path('~').

      Neither of these work on PC since it looks like the variable is HOMEPATH instead. So I was just hoping for a sanity check and wondering what others are doing here. Will this be reliable?

      if (WIN)
        userPath = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
      elsif (MAC)
        userPath = File.expand_path('~')
      end
      
      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        See my code example:
        [ Code ] !autoload.rb loads "!_autoload" folders

        and FYI:

        @unknownuser said:

        ](http://www.ruby-doc.org/core-1.8.6/classes/File.html#M000794)":1laxg9xj]

        File.expand_path(file_name [, dir_string] ) → abs_file_name

        Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless dir_string is given, in which case it will be used as the starting point. The given pathname may start with a **` ~`**’’, which expands to the process owner‘s home directory (**%(#008000)[the environment variable HOME must be set correctly]**.) ~user’’ expands to the named user‘s home directory.

        I'm not here much anymore.

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

          Surely ENV["USERPROFILE"] gives it in one step ?

          TIG

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            As my code does:

            ENV['HOME']=ENV['USERPROFILE'] unless ENV['HOME']
            ENV['USER']=ENV['USERNAME'] unless ENV['USER']
            # now set a global;
            $HOME = ENV['HOME']
            # .. or use the tilde shortcut within pathstrings.
            
            

            BTW.. the " ~*user*" feature does not work on Windows. Likely because of Security issues.

            I'm not here much anymore.

            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