TIP: Use Notepad++ to Count File Types

A few days ago I found myself wanting to figure out how many filenames being written to a log file were JavaScript files. One of the build tasks for an automated build (in VSTS) was logging the names of every file, recursively, beneath the source folder. In this case, there were a total of 15,475 lines written to the build log file. The question I needed to answer was, how many of these files are JavaScript files?

While there are likely many ways to answer this question, I decided to make use of Notepad++ since I already had it installed (it’s my go to text editor). So, how did I use Notepad++ to get the answer? Simple…

Step 1 – Copy Results to Notepad++

Open the build results for the build that you are interested in, select the PowerShell script task in the build results hierarchy, select the log text, copy it to the clipboard then paste it into Notepad++.


Step 2 – Mark All JavaScript Files

Within Notepad++:

  1. Press Ctrl+F to display the Find dialog.
  2. Click on the Mark tab.
  3. Enter “.js\r” (without quotes) to search for all JavaScript files (i.e. files with the .js extension). The “\r” implies we’re looking for the .js extension at the end of a line. If you don’t include the “\r” the results might include other extensions such as .json.
  4. Check the Bookmark line option.
  5. Check the Wrap around option.
  6. Select the Extended option. This is required to take advantage of the “\r” text entered in step 3 above.
  7. Finally, click the Mark All button and click Close.


You will notice that all files with the .js extension have been marked.


Step 3 – Remove Unwanted Lines

Finally, we want to remove all unmarked lines so we are left with only the filenames that we care about. To do this, select the Search->Bookmark->Removed Unmarked Lines menu option.


This will leave you with only the JavaScript files (in this example) remaining, making it easy to determine how many files there are.

There is nothing magical to this approach and you might already have your favorite way to do a count of filenames by type. In my case, I was simply making use of a tool that I already had installed and it took me only a few seconds to get the answer I needed. If you know of an alternative, possibly better, way to achieve the same result, I’d love to hear about it below!

P.S. If you are curious as to how I generated the list of files within a directory on a hosted build agent, check out Get (more) Build Agent Details with PowerShell.