Community
    • Login

    Batch automate "Find in Files"

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    find in filespythonscriptpython
    3 Posts 3 Posters 3.0k 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.
    • Hasso FaliscoH
      Hasso Falisco
      last edited by

      Hey guys, loving the community sofar.

      So here is my question:

      I have a text file containing a list of filenames that looks like this:

      filenameA
      filenameB
      filenameC

      What I want to do is to use Notepad++ “find in files” to search a certain directory for filenameA then search filenameB and so on…
      My end goal is to identify which files returend 0 results.

      Any ideas how to solve this problem? I tried to write a script with PythonScript but I couldn’t find anything in the documentation about “find in files”. Thank you in advance.

      Scott SumnerS 1 Reply Last reply Reply Quote 2
      • Scott SumnerS
        Scott Sumner @Hasso Falisco
        last edited by

        @Hasso-Falisco

        Find-in-files is a Notepad++ feature; the Pythonscript paradigm is more focused on single-document (Scintilla) access. You can see this in the documentation by noticing how many editor. xxx() functions there are versus how many notepad. xxx() functions there are.

        Pythonscript provides two valuable find-related functions: editor.research() and editor.rereplace() . You task needs would presume more interest in the search function. These functions work on a single Notepad++ edit buffer (the currently active tab window), so if you want to deal with multiple documents you have to change the active document yourself (notepad.activateFile()) before searching.

        Overall it is not difficult…but it is not a simple single function call either…

        Another option is to skip Pythonscript for this and go with straight Python, since you hint that you know Python, and nothing in your problem description talks about manipulating text in an open edit buffer (which Pythonscript is adept at). However, it is very much still a “bunch of steps” solution in straight Python as well.

        1 Reply Last reply Reply Quote 0
        • Jim DaileyJ
          Jim Dailey
          last edited by

          @Hasso-Falisco

          Suppose you have a file named FilesToFind.txt that contains:

          filenameA
          filenameB
          filenameC
          

          Open a command window in the directory you want to search. Then enter this command:

          for /F %F in ('type FilesToFind.txt') do @dir /b %F
          

          If you also want to search in sub-directories, use:

          for /F %F in ('type FilesToFind.txt') do @dir /s /b %F
          

          That will spit out a list of the files that exist, which you may be able to use effectively.

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