Tuesday, October 17, 2017

How to find the number of HTML, JPG, etc. files in directories and subdirectories using Windows Power Shell

I wanted to count the number of HTML files in a website, as well as images, etc.

So that I didn't mess up the site I downloaded the files to my Windows 10 computer with FileZilla - a free FTP solution. I then went to the directory containing the documents I wanted to count in the Windows Power Shell - cd changes to a directory, cd .. backs up to the one above where you are.

You can find the Windows Power Shell in Windows 10 by going to the Windows Logo in the bottom left-hand corner of your screen, then choosing All Apps by clicking the bottom icon in the top left-hand corner, then scroll down to W and find Windows Power Shell.

Then I used the command (Get-ChildItem *.*htm* -recurse).count. *.*.htm* was the regular expression I used for a file name (* means anything) because some of the files ended in .shtml and others were .html and maybe some could have been .htm. Then for any files ending in .jp* that gets you jpg or jpeg, plus other variations you type in (Get-ChildItem *.jp* -recurse).count.

Similarly you can count:
 - PDF files with (Get-ChildItem *.pdf -recurse).count
 - PNG image files with (Get-ChildItem *.png -recurse).count


No comments: