Community
    • Login

    Changing default directory

    Scheduled Pinned Locked Moved General Discussion
    4 Posts 2 Posters 5.5k 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.
    • padreP Offline
      padre
      last edited by

      When I start up notepad, it starts with a default CURRENT_DIRECTORY variable that is pointed to the location where the Notepad++ executable is found. I keep my c files in a different directory. Notepad++ is unable to compile the c-files I have defined because the CURRENT_DIRECTORY variable is set to the wrong place. Is there a way to change the value of the CURRENT_DIRECTORY variable? Thanks.

      David

      1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones
        last edited by PeterJones

        Welcome, @padre, to the Notepad++ Community forums

        In Settings > Preferences > Default Directory, do you have it set to ☑ Follow current document?

        Also, what are you using to run the compiler? Run > Run? Or Plugins > NppExec > Run? What command are you passing to that?

        If you’re doing something that just relies on one source file and calling in the right directory, Run>Run of cmd /c gcc "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" could do it…

        For anything more complicated than a one-line command, or anything where directory is critical, I will tend to use NppExec rather than the default Run menu. I usually start with a cd $(CURRENT_DIRECTORY) to make sure that NppExec’s shell moves to be the same as the directory for the current file. For example, to compile then run a c program using a gcc which is in my path,

        npp_save
        cd "$(CURRENT_DIRECTORY)"
        gcc "$(FILE_NAME)" -o "$(NAME_PART)"
        npp_run cmd.exe /k "$(NAME_PART)"
        

        I did a quick experiment: When I have 7.6.4 x64 set to that setting, using Run > Run to cmd /c echo $(CURRENT_DIRECTORY) && pause, it shows the correct value for the $(CURRENT_DIRECTORY) variable. However, if I switch to cmd /k echo $(CURRENT_DIRECTORY) && pause, when it drops to the command line, the working directory is the notepad++.exe executable directory instead. SO it definitely needs the CD. I don’t have time at this moment to debug more and get a command that will work in the Run>Run and do the CD before issuing some other command. (Still, like I said, for multi-command sequences, NppExec is better; I also prefer it, because the results window is embedded in Notepad++, rather than spawning an external cmd.exe, which you have to be careful with /k vs /c and && pause to try to keep the results in a window before it disappears.)

        1 Reply Last reply Reply Quote 2
        • PeterJonesP Offline
          PeterJones
          last edited by

          Okay, able to revisit for a couple more minutes: if you need it to be in Run > Run rather than NppExec, starting from cmd /c cd /d "$(CURRENT_DIRECTORY)" && dir "$(FILE_NAME)" && echo change the dir and this last echo into just the compiler.exe -o "$(NAME_PART).exe" "$(FILE_NAME)" or whatever && pause as the command should get what you want.

          Really, it would simplify down to cmd /c cd /d "$(CURRENT_DIRECTORY)" && compiler.exe -o "$(NAME_PART).exe" "$(FILE_NAME)" && pause – I just had the others to show some more placeholders.

          But still, if possible, I’d recommend NppExec for anything beyond a one-liner (if it needs && to make it work in Run>Run, NppExec will be able to maintain it better)
          `

          1 Reply Last reply Reply Quote 2
          • padreP Offline
            padre
            last edited by

            Thanks. I seem to have it working now.

            1 Reply Last reply Reply Quote 2

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors