[BATCH File] – Count Files in a folder and store it in a variable

Simple batch file commands to count number of files in a folder or directory and then store it in a variable

Step 1: To Count the number of files in a folder including sub-folders.

dir /a:-d /s /b "Folder Path" | find /c ":\" > tempFile.txt

Above command counts the number of files in a folder (mentioned as “Folder Path”) and writes the count number to a text file. Note that replace Folder path in above command with your folder path Example: “C:\Folder”.

Step 2: Write Files count from text file to a Variable

SET /p FilesCount=<tempFile.txt




About the Author


A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

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