Recursively Find Files With Particular File Extension and Content - search

I'm using Windows 10 and the development folders contain a lot of files, I want to search the entire folder tree for a specific keyword but only specific file types.
The folder contains lots of python scripts I want to search only the python scripts for specific keywords. Is there any way to do this with the Windows file search?
Seems like a pretty big omission on something that is fundamental in search.

What do you mean by keyword? Is that a word, present inside the file? Or is it a part of the filename?
In case it's the part of the filename, you can use file: in the Windows search, like in following example:
file:*keyword*.py
This will show you all files, called *keyword*.py. After you've done that, you might change your Windows explorer's view, clicking on the "View" tab and choose "Details", this will also show you the directory where those files are located.

Let's say you want to search the current folder and all its sub-folders recursively for files with the .py file extension that contain the string bar. Open PowerShell in this folder and enter the following command:
Get-ChildItem -Include "*.py" -recurse | Select-String -pattern "bar" | group path | select name
-Include also supports multiple comma-separated file extensions, e.g.: -Include "*.py","*.xml"

Related

Search particular text in all files having same name [Sublime text 3]

I want to search for some text (foo) in all the files having same name in a directory (bar.yml).
I tried using */bar.yml, **/bar.yml, *bar.yml and a whole lot of other combinations in the Where part of find_all, but nothing seems to be working.
Is there a way to do this in Sublime Text 3 ?
Sublime looks for files inside a folder structure recursively, as far as I know.
Open the parent folder structure via File/Open Folder... and open the search dialog via Ctrl+Shift+F. Now add your search term to Find: and your filter bar.yml to Where:. That should do it.

Sublime: Quickly check where file is used?

I often find myself needing to check where a file is used in my node project (which other file imports it). What I'm doing now is right clicking on the editor showing my file, copying the file path, then doing a grep on my whole project using the filename. In this manner I'm able to 'walk up' the dependency tree.
However, I'm wondering if it'd be possible to make a shortcut for this sort of thing. Does anybody know if that's viable?
Include your node project root directory to a sublime project with Project / Add Folder To Project...
Right-click on the project directory in the sidebar, then select "Find in Folder..." from the context menu.
Enable Regular expression
Find: import.*filename
click on Find
filename must be replaced with the actual name. The search pattern can be further refined to match module names from 'filenames', for example. You will end up with a search buffer that lets you jump to each file for that a match has been found.
Maybe Find In Files , Activate with ctrl + shift + F

How to search only in currently open files in vscode?

I usually work on larger projects with many files that would contain the search query. So I would open the files I want to modify and do a find/replace across all currently opened files. Can this be done in vs code?
The feature I'm looking for is implemented in Notepad++, but I'd prefer not to have to switch editors for this task.
For me somehow it works just by typing ./ in the files to exclude field.
The ability to search only in the open editors is in the Stable Build v1.55.
As you can see, the icon is at the end of the files to include input so you will have to have that showing (click the three dots ... just below the search options if files to include is not already showing).
"Search: target particular set of files #20530" located here: https://github.com/Microsoft/vscode/issues/20530
Is tracking a search "scope" such as "all open files".
Hit Ctrl + Shift + F and enable the icon at the end of the 'file to include' text field
I don't think there's a way to do this. You can make a feature request on github. I think an extension could do it though.
There is a checkbox for this in the "files to include" field since version 1.55 (march 2021).
The answer was already mentioned (and accepted above) indeed typing ./ in the files to exclude box of the search window will allow you to only search in open files.
However the response mentioned that he was unsure why this worked. VSCode allows you to exclude all files in a directory by writing the directory in the exclude box. The directory . is the directory where VSCode is opened ie the root directory. The filter ./ excludes all files in the VSCodes root directory so all files are excluded. However opened files ignore any exclude filter. So if you exclude all files only the opened files will be searched.
The best way to find something you are searching for within a specific file in vs code would be:
Ctrl + p then pressing # on the search bar.
It will give you a list of all functions on the file, which makes it easier to track something down.
As an alternative to using Visual Studio Code itself, you can just search the file contents within the folder where unsaved files open in Visual Studio Code are located. This would be in one of these locations depending on which OS you are running:
Linux: /tmp/ (someone else running Linux can verify this)
macOS: ~/Library/Application\ Support/Code/Backups/
Windows: %APPDATA%\Code\User\
This extension is what I use for this purpose.
You may need to change the keybinding if there is a conflict.

IntelliJ File mask not working on simple excluding file pattern! Why?

Follows this page https://www.jetbrains.com/help/pycharm/2016.1/find-and-replace-in-path.html?origin=old_help#mask , it should be able to exclude many files using "!" symbol in front of the regular pattern like: *.java, when doing text search inside IntelliJ projects.
On my project, when I fired Ctrl + Shift + F to do text search for string xyz. There's over 100+ results return in both *.ftl and *.java files. I tried to reduce the results on only ftl files by changing the "File mask(s)"-Option to "!*.java" . But it did not work! The result list is empty!
Googling on the excluding file pattern results in creating custom file filters for each particular search, which I don't want to maintain!
Do I miss something here or IntelliJ is just bad on this function (I'm using IntelliJ 15)? With Eclipse, the "File mask" was amazing!
You have to use
!*.java instead of !.java
As for IDEA 2019.1 Ultimate, it works for me(exclude with !*.yml or anything else).
If it does not in yours, as you only as .ftl file to exclude, why not add mask as *.java?
PS: what does not work is exclude some path, like "all files under out/ folder". With !out/* or anything ales it does not work.
Forget about File Mask and use Scope:
In Scope the options are unlimited where you can select folder include/exclude files or folders.
Excluding file paths in the Find in Path dialogue was not added until IntelliJ 2016.1 per this IntelliJ forum response.

Windows - Search for Files that Do NOT Contain a Certain Term

How would I search for anything in a certain directory that doesn't contain a certain term?
For example:
!(FINAL)
or
NOT(FINAL)
I would like to find anything (files only) that doesn't contain the term FINAL in the title in Windows XP. Is this possible?
Many thanks.
You can search for * NOT *FINAL* for example to find anything without the string final in it
If you are looking for something right from your explorer window, I just did some research since these answers here didnt suffice to me.
To find all php files which do not have "decoded" in their name, I put the following in the search field:
*.php -Decoded
Hope this helps!
Windows Command Prompt
To do this with Windows Command Prompt, CMD.
Start -> Run -> Type "cmd". use "cd" to change to your working directory and enter:
dir | findstr /v /i "FINAL"
This will list all files and folders which do not have the word "FINAL" in the title.
dir /a:-d | findstr /v /i "FINAL"
This will list all files which do not have the word "FINAL" in the title.
POWERSHELL
It is possible to do this with Windows PowerShell.
Get-ChildItem -exclude "*FINAL*"
This will list all files and folders which do not have the word "FINAL" in the title.
Get-ChildItem -exclude "*FINAL*" | where { ! $_.PSIsContainer }
This will list all files which do not have the word "FINAL" in the title.
You may need to download and install Windows PowerShell from here if your installation of XP does not already have it. Windows XP Powershell
Useful Links.
http://technet.microsoft.com/en-us/library/ee176841.aspx
In Windows File Explorer Search Box, type: -
NAME:AAAA (to find documents with AAAA in the title)
NAME:AAAA AND NAME:BBBB (to find documents with both AAAA and BBB in the title)
NAME:XXXX AND NOT:YYY (to find documents with XXXX in the title, but not YYY)
For what is worth, if you do have Total Commander (https://www.ghisler.com/index.htm), it has a pretty good search functionality.
It is able to look into files and has an explicit checkbox "Find files not containing the text"
(note: I am not affiliated with Total Commander in any way, but it is a good tool)
You can use a code like this:
grep -rin "find-what?" ./
You need cmd-bash for this. Makes the work easier!

Resources