Menu

notepad.saveAs(filename): Check if file is open in another program

Help
2017-12-20
2018-01-09
  • Andrey Kazak

    Andrey Kazak - 2017-12-20

    Greetings!

    I use NPP 7.5.3 x86 and Python Script 1.0.8.0.

    notepad.saveAs("D:\t.txt")

    gives

    However

    newFilename = notepad.getCurrentFilename() + ".changed" 
    notepad.saveAs(newFilename); 
    

    works as designed.

    What could be the root cause for this?
    Thank you.

     

    Last edit: Andrey Kazak 2017-12-20
    • David Hansen

      David Hansen - 2017-12-21

      I believe some anti-virus softwares will prevent changes to the host file. A windows service might also have a lock on it. Here are some things to try:
      - Right click the file and make sure its not Read-Only
      - Run N++ as administrator and try to edit it again
      - Reboot into safe mode and edit it
      - Save it as .changed and use the windows console or python library to copy the file to hosts
      - Find which process is using the file and kill it.

       
  • Andrey Kazak

    Andrey Kazak - 2017-12-22

    Dear David,
    Thank you.
    Running N++ as administrator solved the issue.

    However I do not see the crucial difference between
    notepad.saveAs("D:\t.txt")
    and
    newFilename = notepad.getCurrentFilename() + ".changed"

     
  • David Hansen

    David Hansen - 2018-01-09

    Yeah, my intuition would also say that your notepad.saveAs() should work, but it must still require that the hosts file be unlocked.

    Have you tried saveAsCopy()? I'm thinking that notepad.saveAsCopy("D:\t.txt") should do what you are expecting...

    Notepad.saveAs(filename)
    Save the current file as the specified filename

    Notepad.saveAsCopy(filename)
    Save the current file as the specified filename, but don’t change the filename for the buffer in Notepad++

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.