Automatically selecting files with searched word in it
-
Hi guys, I’m fairly new with this program and I’ve got a question.
I searched for a word in a directory, and it found occurrences in 220 files. Is there a way to automatically select and copy/paste those files in another directory?
Thanks a lot! -
Automatically? No.
But with a “few” steps, not so hard:
- right-click in the Find result panel whitespace (anywhere)
- choose Select All from the popup menu
- press ctrl+c to copy
- create a new file called
test.batin your desired destination directory - open
test.batin Notepad++ - press ctrl+v to paste into N++'s buffer for
test.bat - choose Edit (menu) > Line Operations > …and pick the topmost sort option
Your file buffer should now have a group of lines at the top that start out with
Lineand a group of lines at the bottom that start withSearch. You want the grouping of lines in the middle, the ones that start out with actual pathnames and end with(# hits)- manually remove the
Linelines at the top of the file - manually remove the
Searchlines at the bottom of the file - run this regular-expression replace on the whole file: Find:
(?-i)\s\(\d+\shits?\)(?=\R)Repl:" . - run this regular-expression replace on the whole file: Find:
^\s+Repl:copy " - press ctrl+s to save
test.bat - get a cmd prompt in the directory containing
test.bat - type
testat the prompt and press Enter - WATCH THE CMD OUTPUT AS ALL OF YOUR FILES ARE COPIED INTO THAT SINGLE DIRECTORY!
- delete the
test.batfile
Note that this won’t work so well if any files have the same name (just the name.ext part) which can happen. Be careful.
Wow. I usually don’t give explanations like that. I think I am channeling @guy038 while he is off fishing. :)
-
I didn’t quite manage to get the last part right, anyway just simply having the paths displayed like that helped me save quite a bit of time.
Thanks a lot! -
Good that you got something you could use from that!
Actually, this is probably a good opportunity to show off macros in Notepad++.
First, do some (one-time) setup:
- Press the toolbar button for starting macro recording
- In an editing tab view, press an arrow key to move the caret (this is just a dummy action)
- Press the toolbar button for stopping macro recording
- Press the toolbar button for saving a recorded macro; give it the name
Bat file from Find resultsand save it - Exit Notepad++
- Restart Notepad++
- Locate your
shortcuts.xmlfile and open it in Notepad++ - Do a find on
Bat file from Find resultsand you should be left looking at something like this:
<Macro name="Bat file from Find results" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="0" message="2306" wParam="0" lParam="0" sParam="" /> </Macro>- Replace the
Actionline with the following block, making the indent level of the block match that of the oldActionline:
<Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)^Search.+\R" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="770" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)^\tLine.+\R" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="770" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="\s\(\d+\shits?\)$" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam='" .' /> <Action type="3" message="1702" wParam="0" lParam="770" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="^\s+" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam='copy "' /> <Action type="3" message="1702" wParam="0" lParam="770" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />- Save the
shortcuts.xmlfile - Exit Notepad++
- Restart Notepad++
That’s the end of the one-time setup. That will remain until you delete the macro created.
To use it, each time you need to:
- Run a Find-in-Files search that results in several hit files
- Copy and paste the Find-result panel results (per the earlier instructions on how to do that) into an empty Notepad++ tab (an empty file called
test.batmight be appropriate!) - Go to the Macro menu and choose
Bat file from Find resultsfrom near the bottom; you should observe your file of search results has changed into a bunch ofcopybatch file commands (this step “runs” the macro consisting of several replacement operations!) - Save the file
- Continue from the earlier instructions at step
get a cmd prompt in the directory containing...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login