Basic Scripting question

2011-02-22
2012-11-14
  • Cory Plowman
    Cory Plowman
    2011-02-22

    Hi Guys,

    I'm new to this whole scene, but basically I wanted to know how to get Notepad++ to monitor a folder and when a new file is dropped into it to open it, and search a replace a text string, then save the file to a new directory. Is this possible?

     
  • Sorry for the delay in reply - I'd missed this message somehow.

    I've just checked, and at the moment there don't seem to be any libraries for Python to do file/directory "monitoring", although it is supported by the OS.  Personally, I wouldn't use Notepad++ for this - a little .NET application would be simpler to write, and also simpler to use, as you wouldn't have to run N++ somewhere, just for this purpose. 

    Have a look at FileSystemWatcher in C#.

    Cheers,
    Dave.

     
  • Dev Player
    Dev Player
    2011-09-13

    coryplowman,

    Although this reply is past due; there is a ton of stuff referring to monitoring a folder or file using Python. There are Python several libraries too that deal with this. You can check PyPI - the Python Package Index at:
    http://pypi.python.org/pypi
    On that webpage you will see a box in the upper leftish called "Getting Packages" and a URL link

    or
    http://pypi.python.org/pypi?%3Aaction=browse
    where you will see a Search box in the upper right of the webpage for what you want to search for. Be aware the site seems slow as it indexes some 10k+ packages (perhaps inefficently).

    Usually watching for a folder (or file) is done with "polling". There's lots of stuff on Google. Try googling: python file polling
    You will see tons of stuff for polling and non-polling.

    I agree with davegb3 that Notepad++ is not designed as a OS file monitoring tool; although if you have a text file opened for editing and some other program modifies that file, when you click back onto notepad++ and the tab of that file, notepad++  will popup a window saying something about the file being changed.

    Here's some more info:
    Detect File Change Without Polling
    http://stackoverflow.com/questions/5738442/detect-file-change-without-polling