Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 3.7k 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

      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.

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @瀚程戴
        last edited by

        @瀚程戴
        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
        • XP1X
          XP1
          last edited by XP1

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

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

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @XP1
            last edited by

            @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 瀚程戴

              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
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors