• Login
Community
  • Login

Is there a way to set %USERNAME% in the path?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 3.9k Views
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.
  • 瀚
    瀚程戴
    last edited by Dec 22, 2015, 4:11 AM

    I saved a workspace in two computers with different user names like this:

                <File name="C:\Users\MyUsername\project\filename.docx" />
    

    My question is, is there a way to let Notepad++ know the username automatically?
    For example, like in batch command, if you echo %USERNAME%, then " %USERNAME%" will be replaced by your actual user name.

    C 1 Reply Last reply Dec 22, 2015, 1:27 PM Reply Quote 0
    • C
      Claudia Frank @瀚程戴
      last edited by Dec 22, 2015, 1:27 PM

      @瀚程戴
      There a different ways to do this. The question is what do you exactly expect?
      Should npp replace a variable if you open a file or if you save it or close it …
      Maybe you can give us a short example what you want to achive.

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 0
      • X
        XP1
        last edited by XP1 Dec 22, 2015, 2:23 PM Dec 22, 2015, 2:22 PM

        @瀚程戴 is talking about the session file from File > Save Session…

        It looks like Notepad++ does not resolve the path containing an environment variable.

        C 1 Reply Last reply Dec 22, 2015, 7:38 PM Reply Quote 0
        • C
          Claudia Frank @XP1
          last edited by Dec 22, 2015, 7:38 PM

          @XP1 @瀚程戴

          afaik npp doesn’t expand environment variables in this case.
          What could be done so is to use a python script like

          import os
          
          for _file in notepad.getSessionFiles('PATH_SESSION_FILENAME'):
              notepad.open(os.path.expandvars(_file))
          

          where PATH_SESSION_FILENAME needs to be replace with your session file, of course.

          If this python script should be executed right after npp started you need to copy the lines
          to startup.py file and change initialisation to ATSTARTUP in python script configuration window.

          Cheers
          Claudia

          1 Reply Last reply Reply Quote 0
          • 瀚
            瀚程戴
            last edited by 瀚程戴 Dec 24, 2015, 1:02 AM Dec 24, 2015, 1:00 AM

            You guys got my point although I didn’t make it clear enough. It’s a pity that npp could not get an environmental variable.
            Just let you know my demand better and my solution in R:

            library(R.utils)
            user <- System$getUsername()
            directory <- paste(“C:\\Users\\”, user, “\\workspace”, sep=“”)
            setwd(directory)

            With the above code, I could set the working directory correctly regardless of which computer I use, so it’s easy for me to switch different computers.

            I’m just a beginner of Python, however, I will learn your script @Claudia-Frank .
            Thank you all!@XP1 @Claudia-Frank

            1 Reply Last reply Reply Quote 0
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors