Notepad3 icon indicating copy to clipboard operation
Notepad3 copied to clipboard

Notepad3 always creates new files in its Program Files directory

Open chipplyman opened this issue 1 year ago • 5 comments

Repro:

  1. cd c:\mydirectory
  2. c:\Program Files\Notepad3\Notepad3.exe foo.txt
  3. Answer Yes when notepad3 asks if you would like to create the file
  4. Save
  5. Quit
  6. Repeat step 2

Expected result:

  • c:\mydirectory\foo.txt exists after step 4 and is re-opened at step 6
  • The working directory of Notepad3 is c:\mydirectory
  • Notepad3 looks only in the working directory for the file specified on the command line. It does not look in its own exe directory or in the PATH for that file.

Actual result:

  • c:\Program Files\Notepad3\foo.txt exists after step 4 and is re-opened at step 6
  • Notepad3's working directory is c:\Program Files\Notepad3
  • If a file is specified that does not exist locally or in the exe directory, it may be opened from some arbitrary location specified in the PATH.
  • This occurs even if I specify .\foo.txt or ..\mydirectory\foo.txt, which both should unambiguously signal that I want only a file in the current directory
  • The only way I can find to ensure that my file is created or opened from where I expect is to specify a full path

Remarks: I see in the Process Start event in Process Monitor that notepad3.exe starts in c:\mydirectory. At some point during initialization, it changes its working directory to the exe location.

I can think of zero valid use cases for searching in the PATH for a text file. The PATH is intended to be used for locating executable files.

chipplyman avatar Oct 01 '24 18:10 chipplyman

Program Files shouldn't be touched, would raise UAC everytime.

mrx23dot avatar Nov 06 '24 09:11 mrx23dot

I second this. Exact same thing happens to me, running the latest release version 6.24.1221.1 x64.

This is not normal behavior, and it's very annoying because whenever I create a file, I think in the working directory, and then go to use it, it's not there and I have to move it from the (portable) install location.

I'm not sure I've ever seen another file-creating application behave like this.

Importantly, native Windows Notepad and Notepad2 do not do this.

notepad new_text.txt

edits a file in the current working directory, as one would expect.

tgice avatar Mar 18 '25 20:03 tgice

Update, after finding duplicate issue #5106, I tried again (since that one reported an earlier version that I'm running having fixed this).

I found the same behavior on that other #5106 version, but then figured out what might be causing this for me at least.

I'm usually calling Notepad3.exe via a symlink (I tried it with hardlinks too and the same problem happens), mostly just to rename the executable from notepad3 to n, for faster calling on the command line.

I'm guessing it's maybe because of that that this pathing issue is happening. The default path that Np3 uses for the file is the path that the symlink exe is in, not the true exe.

Oh, and it appears that the issue only comes up if the path the symlink exe is in is not the same as the true exe path, for anyone trying to replicate the bug.

Would still appreciate if this could be fixed. Thanks!

tgice avatar Mar 18 '25 20:03 tgice

An easy workaround is to define your "DefaultDirectory" in "Notepad3.ini" in section "Settings2 (see picture). 🤔

Image

hpwamr avatar Mar 18 '25 23:03 hpwamr

Program Files is a system directory and is by default unwriteable. I suggest we make this home directory instead.

lhmouse avatar Mar 19 '25 13:03 lhmouse