• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Email Me
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
madbray.com

madbray.com

The WP Experiment

  • Home
  • Blog
  • Shop
  • Contact
  • About

Count Files of a File Type In a Directory

September 11, 2021 by Brad May Leave a Comment

In Windows, you can use the command prompt (cmd.exe) to count how many files of a specific file type are in a directory. You can also include files in sub-directories in this count.

My specific use case was that I needed to find out how many PHP files (.php) were in my project so I could tune OpCache correctly using the setting opcache.max_accelerated_files. Here’s how I did it…

Count Files in CMD Prompt

  1. Open cmd prompt (click Start -> type “cmd”)
  2. Run this command:
dir /s /b "c:\<path to your files>"\*.<file type> | find /c ".<file type>"

Example Count Command

Windows command prompt example command: dir /s /b "c:\inetpub\wwwroot"\*.php | find /c ".php"
dir /s /b "c:\inetpub\wwwroot"\*.php | find /c ".php"

DIR Command Switches

/s = include sub-directories

/b = uses bare format (no headers) in the “dir” command’s output

FIND Command Switches

/c = counts the number of times the search term appears

Explanation

Using the ” | ” (pipe) operator, you are running the “dir” command to generate a list of files, then you are “piping” (or sending) that command’s output INTO another command as the input. In this case, we’re making that list of files be the input of the “find” command.

Make sure you substitute <path to your files> for the path in your file system. Also, you can use this to look for files of any file type, not just .php.

Conclusion

I hope this helped save you some time. Send me a message or leave a comment below if you have any questions!

Share this:

  • Twitter
  • Facebook

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Join the WP Experiment

Top Rated Stuff

  • madbray.com coffee mug Coffee Mug - The Official Coffee Vessel $15.80
  • hand me a burrito t-shirt "hand me a burrito" t-shirt $27.40
  • Another Official Coffee Vessel $18.10

Connect With Me

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Recent Posts

  • How to Turn Off AT&T DNS Error Assist
  • Android 12 Update: How to Choose Browser to Open Links
  • Easy Fix: Act! “Access to the path is denied”
  • How to Fix: Veeam Backup & Replication Agent Install Failed
  • ClickBank Account Disabled After Completing Profile: How to Fix

Footer

Popular Posts

  • How to Turn Off AT&T DNS Error Assist
  • Android 12 Update: How to Choose Browser to Open Links
  • Easy Fix: Act! “Access to the path is denied”
  • How to Fix: Veeam Backup & Replication Agent Install Failed
  • ClickBank Account Disabled After Completing Profile: How to Fix

Tags

access denied Android asterisk at&t backup beach branch change chan_sip cisco 7960 clickbank cmd command prompt database electric guitar encryption Essentialism firefox freepbx genesis google docs Greg McKeown growth internet mailchimp mysql online business passwords pjsip plugins remote desktop res_pjsip security sip siteground sunrise survey monkey veeam web hosting Windows WordPress WordPress development worship practice

Topics

  • Faith (7)
    • Bible Verses (1)
  • Musings (8)
  • Online Business (7)
  • Projects (4)
  • Technology (19)
  • Uncategorized (1)
  • WordPress (6)
    • Development (1)

Copyright © 2023 · Kreativ Pro On Genesis Framework · Proudly running on WordPress

Here from Fortnite? ~~~~~ Dismiss