If you save your files in a common location, then your saved files should be indexed. So searching by name will usually get you what you’re looking for. But what if you want to find a line in your code? Or how many of your scripts use a specific command? Unfortunately, this doesn’t happen out of the box in Windows. The default for most file types is only to filter on properties. However, it only takes a quick few clickety-clicks to change your life forever by searching the content of your code and not just the properties. So without further ado, let’s do this thing!
Before we go any further, if your files are saved outside of the common locations like Documents, Desktop, or almost anywhere else in your user profile, you’ll want to add it. First, click “Modify” to see the current directories being indexed. Browse to your code directory, check the box, and then click “Ok.” It’s easier than extending your vehicle warranty.
Now that we have our locations indexed, we want to change the filter on our specific file types. To begin, click “Advanced” and then click the “File Types” Tab. For Python, look for .py. For PowerShell, look for .psm1, .ps1, .ps2, ps3. ps4…maybe not those last PlayStations, but you catch my drift. Highlight each file type you want to be able to search the contents of and then click the “Index Properties and File Contents” bubble. When you’re finished, click “Ok” to save your changes.
\\\but does it actually work???
Like all good IT scientists, we empirically validate our experiments before we start flapping our gums and fire off emails claiming “we’ve found the issue!” Open up Windows Explorer and in the top right search bar type in your deepest darkest secret line you want to find. As an example, I’m going to search for a variable I used in the post about Quickly Testing APIs in PowerShell. Let’s see if we do in fact have the Midas touch.
And that’s that! This was easier than falling off the edge of the flat Earth and getting eaten by a turtle. Since you have indexed your scripts for Windows Search, you can now easily search any of the contents of your scripts/code. Gone are the days for extremely long file names or making your own cheat sheets of what’s in each of your files. Go rest now from all of your arduous labor.