Community
    • Login

    Locking file from other editing while opened in Notepad++

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 5 Posters 7.5k 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.
    • Elin PetterssonE
      Elin Pettersson
      last edited by

      Is there any way to lock a file from being edited by other users while I have it opened i n Notepad++?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Elin Pettersson
        last edited by PeterJones

        @Elin-Pettersson ,

        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.
        e3bcc5a2-4f1f-42bb-af19-bf6401bc6d83-image.png

        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 cacls might be able to lock or unlock files; this page indicates that cacls <file> /P everyone:n will lock and cacls <file> /P everyone:f will 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
          • Cancel
        • 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 cacls is designed)

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

          …
          Oh, when trying it out, the cacls method unfortunately prevents Notepad++ from saving the file, too. That’s why flock or I think LockFileEx would 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.

          1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn
            last edited by

            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.

            PeterJonesP 1 Reply Last reply Reply Quote 3
            • PeterJonesP
              PeterJones @Alan Kilborn
              last edited by

              @Alan-Kilborn ,

              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.

              1 Reply Last reply Reply Quote 2
              • Serpens66S
                Serpens66
                last edited by

                Hello,
                I did not find a more recent thread with that topic, please link me to one if there is one.

                I use notepad++ 8.7.5 and noticed that in this or some of the latest versions this “locking from files” or at least folders was introduced. How do I disable that feature?
                Notepad++ prevents me from changing the folder name of opened files. And it even still prevents it, even after I closed all related files. I have to completely close notepad++ to release this lock.

                1. It seems to be a bug that closing the files does not release the folder.
                2. I want to disable this feature, since I frequently want to change folder names of opened files. How to do this?
                xomxX 1 Reply Last reply Reply Quote 0
                • xomxX
                  xomx @Serpens66
                  last edited by

                  @Serpens66

                  Do you have the XML Tools plugin installed in your Notepad++?

                  Serpens66S 1 Reply Last reply Reply Quote 0
                  • Serpens66S
                    Serpens66 @xomx
                    last edited by

                    @xomx Hi, thank you very much. Yes indeed I installed that xml Tool ~ a month ago. Would indeed match the time when this started happening, thank you very much :)
                    Do you know how to disable this behaviour in XML Tool Plugin?

                    xomxX 1 Reply Last reply Reply Quote 0
                    • xomxX
                      xomx @Serpens66
                      last edited by

                      @Serpens66 said in Locking file from other editing while opened in Notepad++:

                      Do you know how to disable this behaviour in XML Tool Plugin?

                      Uncheck in menu > Plugins > XML Tools > “Enable XML syntax auto-check”:
                      https://github.com/notepad-plus-plus/notepad-plus-plus/issues/16643#issuecomment-3136799846

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