LuckyLucks
asked on
Counting total files in a folder including subdirs
Hello,
I was working on a batch script to count all the files inside a folder. The folder includes two level of sub directories. Only the lowest subdirectory contains files of different formats - csv, pdf, txt, doc, docx.
So, Alphabets has 27 subfolders A-Z and Number. Under A, I will have a level of subdirs like Apple, Apollo. Under each of these subdirs there will be the files. I need to count all such files.
Alphapbet
A B C - Z number
Apple Apollo 1
a1.pdf a2.pdf a3.pdf 3muskateer.pdf
So total file count is 4.
I was working on a batch script to count all the files inside a folder. The folder includes two level of sub directories. Only the lowest subdirectory contains files of different formats - csv, pdf, txt, doc, docx.
So, Alphabets has 27 subfolders A-Z and Number. Under A, I will have a level of subdirs like Apple, Apollo. Under each of these subdirs there will be the files. I need to count all such files.
Alphapbet
A B C - Z number
Apple Apollo 1
a1.pdf a2.pdf a3.pdf 3muskateer.pdf
So total file count is 4.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you try it?
Yes, if all you are looking for is a total count the solution Steve presented will do that. I saw the question, saw his answer, and said "nothing to add here" and moved on...
~bp
~bp
ASKER
Is it possible to add a user input parameter so that I can run it like :
> count.bat A:\All
> count.bat B:\
> count.bat A:\All
> count.bat B:\
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://scripts.dragon-it.co.uk/links/batch-gui-folder-mk2
If you incorporate the script into above script of mine you can either use the command line, drag a folder onto the icon using explorer, or if not then it uses a windows dialog box to ask you to choose the folder.
Steve
If you incorporate the script into above script of mine you can either use the command line, drag a folder onto the icon using explorer, or if not then it uses a windows dialog box to ask you to choose the folder.
Steve
OK getting a bit silly for a batch file but.... drag folder onto it, type on command line, or select using GUI if not....
@echo off
REM Script from: http://scripts.dragon-it.co.uk/links/batch-gui-folder-mk2
set folder=
if "%~1"=="" (
echo No folder selected.
call :getfolder
) ELSE (
if exist "%~1" (
set folder=%~1
) else (
echo Folder not found or you have passed a filename instead
pause
exit /b
)
)
if "%folder%"=="" exit /b
pushd "%folder%
for /f %%a in ('dir /b /s /a-d ^| find /v "" /c') do set count=%%a
call :MessageBox "There are %count% files under %folder%"
exit /b
:GetFolder
(echo Set objShell = CreateObject^( "Shell.Application" ^)
echo set objFolder = objShell.BrowseForFolder^( 0, "Select a folder", ^&H10^&, ""^)
echo if objFolder is nothing then wscript.quit
echo wscript.echo objFolder.Self.Path)> "%temp%\getpath.vbs"
for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getpath.vbs"') do set folder=%%a
exit /b
:MessageBox
set heading=%~2
set message=%~1
echo msgbox WScript.Arguments(0),0,WScript.Arguments(1) >"%temp%\input.vbs"
START "" Wscript //nologo "%temp%\input.vbs" "%message%" "%heading%"
exit /b
CountFiles.cmd
ASKER
Alphabets
A B C 1
Apple Appolo 3muskateers
a1.pdf a2.pdf c1.pdf 3 muskateers.pdf
So a total of 4 files.