Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Open files & keyword search&Proc...

reachspk
2012-04-10
2013-01-25
  • reachspk
    reachspk
    2012-04-10

    Dear All,

    Can someone please help me out in generating a macro to open the files (in notepad++.exe) associated with a particular "INCLUDE" statement and also Find/search the uer-input keyword and process the opened files accordingly?

    Algorithm: for your kind reference.
    1. a) If the macro1 is run in a notepad++.exe, it should search for the INCLUDE statements available inside the current file and open all files associated with the INCLUDE statements.
    for example: INCLUDE 'C:/test1/A_01_prog.txt' - this statement will be avilable in the current notepad file.
    All files are available in folders, say A, B, C and the macro should be capable of searching 'n' number of subfolders inside the main folder)
    b) All the files (in the INCLUDE statement) should be opened in a single Notepad++ session

    2. a) If the macro2 is run, it should find a specified text (user enter via a GUI) in all files opened in Notepad++ session. i.e., In the dialog box, text or number to be found is entered. (Regular expressions can be used - eg. (1234 l 7890 means look for 1234 or 7890).
    This macro should also close all files in Notepad++ session which doesn't have the specified text

    Finally, please use the generic path as C:/test1/ to reference all files. Please find the "test1.zip" in the link attached below. - just for your reference. (I guess this macro can be developed without these sample files too)
    http://www.excelforum.com/excel-programming/823416-open-wordpad-notepad-txt-files-via-vba-macro-and-search-for-a-keyword-and-process-the-files.html
    Unzip the attached "test1.zip" and process the files accordingly.

    Requesting you to please get me for the macro satisfying te above algorithm.

    Thanks in advance!

     
  • To open a file, use notepad.open()

    To get the text of the current line, use

    editor.getLine(editor.lineFromPosition(editor.getCurrentPos())
    

    See notepad.prompt() for prompting the user for input. 

    I think you'd have more luck if you had a go at writing this, and ask when/if you get stuck - you might get lucky and find someone wanting a challenge though…. :)

    Dave.

     
  • reachspk
    reachspk
    2012-04-16

    Hi Dave,

    Thank you for your response.

    But my Macro code requirement is a bit different as mentioned in my original post. I have written down a macro in "Nedit text editor" for the Algorithm 1 mentioned in my previous post. Code is as follows:
    #Macro1
    beginning_of_file()
    find("(?<=^INCLUDE').*?(?=')","backward","regex")
    lastline=$line
    beginning_of_file()
    while(lastline!=$line)
    find ("(?<=^INCLUDE').*?(?=')","forward","regex","wrap")
    open_selected()
    }

    For Algorithm 2, macro written in Nedit text editor is as follows:
    #Macro2
    * Ask the user what to look for to fill with
    finditem = string_dialog("find?", "OK", "Cancel")
    if($string_dialog_button ==2 !! $string_dialog_button == 0)
    return

    window = focus_window("last")
    while(""!=window)
    {
    # do your work here
    # raise_window()
    a=search(finditem,0,"regex")
    if(a==-1)
    {
    close()
    }
    window=focus_window("next")
    }

    I guess the code written above is self-explanatory and you could find the algorithm explanation in my previous post.
    Could you please modify the above code so that these macros work with notepad++. As I am a new user of notepad, I am not much aware of the syntax of each commands being used.

    Please let me know if you have any questions.

    Thanks in Advance,
    Prakash

     
  • Sorry, this is a help forum, for people with specific questions or issues relating to the Python Script plugin, not a free script writing service.  If I (and everyone else that writes scripts regularly) wrote everyone elses scripts, we'd never do anything else. There is ample documentation to get you started, and converting your existing script should just be a matter of changing the syntax, and the few N++/scintilla specific calls.

    If you want me to write this, that's a commercial request, and it would be 100 euros.

    Cheers,
    Dave.