Locking file from other editing while opened in Notepad++
Is there any way to lock a file from being edited by other users while I have it opened i n Notepad++?
Sorry. As far as I know, file locking has never been added to Notepad++.
It’s a good idea, at least as a feature that can be optionally enabled; some people like Notepad++'s feature that it can watch for external changes to the file and update it, so not everyone would want that enabled. But if it were made a menu option in the edit menu, like the set and clear read-only commands, maybe with an enable/disable cirlce, similar to what’s in the language menu, that would make sense to me.
I know that back in late 2019, someone else asked here whether file locking would be implmented. That user was told that they could create an issue, but when I searched the issues, I couldn’t find mention that they ever made that feature request. The forum has a FAQ Entry on Making Feature Requests.
If you would like to make the feature request, feel free to follow that FAQ’s instructions. (Since I agree with the feature request, I would make it myself, but the developers tend to take feature requests from “regular users” as having more weight than requests from power users and those of us who hang out in the forums, so that’s why I am encouraging you to put in the feature request)
At one point, I thought someone had asked, and that someone had presented a way to lock and unlock a file using the Run menu (and thus be able to save it using Run > Run > Save…), but I went more than a year back in the forum search, and didn’t find any that looked like they actually matched my memory. A quick web search tells me that the Windows command
caclsmight be able to lock or unlock files; this page indicates that
cacls <file> /P everyone:nwill lock and
cacls <file> /P everyone:fwill unlock it… though that appears to be really changing permissions rather than a true lock, like
flock()from the linux world or I think
LockFileEx()from win32 libraries.
In the Config File: Macros section, the usermanual describes some variables you can use in Run > Run commands. So to make those two commands available, you can try:
Run > Run
cacls "$(FULL_CURRENT_PATH)" /P everyone:n
- Save… >
Lock File, set a keyboard shortcut if desired, and click OK when done
- Cancel – I know, that’s counter-intuitive. Either Run or Cancel will work here, though Run will try to lock the active file, whereas Cancel will exit the dialog. The OK above is what actually saved
Run > Run
cacls "$(FULL_CURRENT_PATH)" /P everyone:f
- Save… >
Unlock File, set a keyboard shortcut if desired, and click OK when done
At this point, the Run menu will now contain a Lock File entry and an Unlock File entry, which will run those commands (and a cmd.exe window might pop up asking for confirmation – that’s the way
Oh, when trying it out, the
caclsmethod unfortunately prevents Notepad++ from saving the file, too. That’s why
flockor I think
LockFileExwould be better.
Those are best done from inside Notepad++ executable. But one of the scripting-plugin experts might be able to come up with a way to flock the file from a script will still allowing Notepad++ to edit the file.
Perhaps from @PeterJones ’ showing of the menu with items Set Read-Only and Clear Read-Only Flag , users might get excited and think, Oh, all I need to do is “Set read-only” and I’m good, thinking of the “read only” attribute of the file system.
So maybe it is worth pointing out that Set Read-Only merely sets Notepad++'s own internal status to not allow this file to be changed, by the individual having it open in N++. It does nothing for how the computers of other users see this file (i.e., nothing for the file system attribute).
Note of contrast: Clear Read-Only Flag is the one that actually does affect the file system attribute. I’ve always found it interesting that these two commands are not really complementary.
Thanks for that clarification. Yes, the Set Read Only is a toggle (I guess it uses a ✔, not a ⦿). And Clear Read-Only Flag might be better phrased Clear OS Read-Only Flag.