Do you have a little more information on how this works ?
Main Topics
Browse All TopicsHello,
Is it possible to specify another folder on the computer and work out the number of files within it (even in subfolders) and its size and output it to screen ?
GISVPN
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Of course, it was just a "teaser" ;-)
robocopy is used to copy or move big amounts of data between two locations (folders, computers). It is able to compare for date change, even date (older than x days, for example).
Here it is just used to collect statistics about the files (the order of options is not relevant):
. . . is current folder, and it is used both as source and target,
/is because this tells robocopy to include same files (which it would omit
without that switch). While comparing . with . all files are the same, obviously.
/njh No Job Headers (source folder, destination folder, resulting switches used)
/L List only, do not copy or move
/S with subfolders
/nfl /ndl No File List, No Directory List
The combination of the no flags (/njh /nfl /ndl) will result in only the summary shown.
Please try the following simple batch file. You can run the batch file with or without a foldername as a parameter.
:: ==========================
:: folderstat.bat
:: ==========================
@echo off
if not exist "%~1\" (
echo.
echo Folder %1 does not exist
exit /b 1
)
set FolderCount=0
set FileCount=0
set FileSizeSum=0
for /f "tokens=*" %%a in ('dir /ad /b /s %1') do (
set /a FolderCount+=1
)
for /f "tokens=*" %%a in ('dir /a-d /b /s %1') do (
set /a FileCount+=1
set /a FileSizeSum+=%%~za
)
echo.
echo Folder %1 contains %FolderCount% Folder(s) and %FileCount% file(s)
echo Total size of %FileCount% file(s) = %FileSizeSum%
Qlemo
I'm paying attention...
Hmmmm... 32-bit precision eh?.... Okay, I can do that.... Thank you for your suggestion.
gisvpn
Please see the modified code which splits the output into GB, MB, KB and Byte sizes (just in case your total file size exceeds 2TB).
@echo off
setlocal enabledelayedexpansion
if not exist "%~1\" (
echo.
echo Folder %1 does not exist
exit /b 1
)
set FolderCount=0
set FileCount=0
set FileSizeB=0
set FileSizeKB=0
set FileSizeMB=0
set FileSizeGB=0
for /f "tokens=*" %%a in ('dir /ad /b /s %1') do (
set /a FolderCount+=1
)
for /f "tokens=*" %%a in ('dir /a-d /b /s %1') do (
set /a FileCount+=1
set /a FileSizeB+=%%~za
set /a FileSizeKB+=!FileSizeB! / 1024
set /a FileSizeB=!FileSizeB! %% 1024
set /a FileSizeMB+=!FileSizeKB! / 1024
set /a FileSizeKB=!FileSizeKB! %% 1024
set /a FileSizeGB+=!FileSizeMB! / 1024
set /a FileSizeMB=!FileSizeMB! %% 1024
)
echo.
echo Folder %1 contains %FolderCount% Folder(s) and %FileCount% file(s)
echo.
echo Total size of file(s) = %FileSizeGB%GB %FileSizeMB%MB %FileSizeKB%KB %FileSizeB%Bytes
As it stands, you could specify what folder to look at by passing the full path, or relative path as a command line argument as in:
FOLDERSTAT c:\windows\temp
or (parent folder) as in:
FOLDERSTAT ..\
etc...
NOTE: As with DOS, if your path contains spaces then you need to enclose it in double-quotes as in:
FOLDERSTAT "C:\Documents and Settings\Paul\My Documents"
or you could hardcode the path/folder into the code itself. I have modified the code so that you only need to edit a single line - the third line of code. Do not use double-quotes if hardcoding the path in the batch file.
Replace 'c:\windows\temp' on the 3rd line to whatever folder you want to look at:
@echo off
setlocal enabledelayedexpansion
set TargetFolder=c:\windows\te
if not "%~1"=="" (
set TargetFolder=%~1
)
if not exist "%TargetFolder%\" (
echo.
echo Folder %TargetFolder% does not exist
exit /b 1
)
set FolderCount=0
set FileCount=0
set FileSizeB=0
set FileSizeKB=0
set FileSizeMB=0
set FileSizeGB=0
for /f "tokens=*" %%a in ('dir /ad /b /s %TargetFolder%\') do (
set /a FolderCount+=1
)
for /f "tokens=*" %%a in ('dir /a-d /b /s %TargetFolder%\') do (
set /a FileCount+=1
set /a FileSizeB+=%%~za
set /a FileSizeKB+=!FileSizeB! / 1024
set /a FileSizeB=!FileSizeB! %% 1024
set /a FileSizeMB+=!FileSizeKB! / 1024
set /a FileSizeKB=!FileSizeKB! %% 1024
set /a FileSizeGB+=!FileSizeMB! / 1024
set /a FileSizeMB=!FileSizeMB! %% 1024
)
echo.
echo Folder %TargetFolder% contains %FolderCount% Folder(s) and %FileCount% file(s)
echo.
echo Total size of file(s) = %FileSizeGB%GB %FileSizeMB%MB %FileSizeKB%KB %FileSizeB%Bytes
echo.
have you changed the code in any way?
are you passing any command line arguments, if so, what?
are you running the batch file under XP, if not, what operating system?
are you running the batch file in a COMMAND session or a CMD session?
if you know how to perform a screen copy (by increasing CMD's screen buffers to say 400, remove the first line @echo off, clear the screen, run the batch file, mark and highlight the output, hit enter. and paste into a text file) you could post the output for inspection so that I can see where the problem occurs.
Hello,
please see the screenshots below. The first screenshot shows the script as I see it. The second is with echo on..
Another strange thing that I noted it that it also reports the incorrect number of folders and files :
The script reports :
42 folders and 147 Files .... however Windows says its 42 Folders and 139 files....
Also the sizes identifed are different, I am therefore assuming that there are a number of files it cannot read and count ?
:)
rplace the 2nd FOR block with the following tempoary code (including the enclosing brackets). run the batch file and inspect the file OUTPUT.TXT by typing:
MORE < output.txt
None of the square brackets should be empty. Post a copy of the text file. My guess is it's missing the filesize in the 2nd SET statement in the 2nd FOR loop.
(for /f "tokens=*" %%a in ('dir /a-d /b /s %TargetFolder%\') do (
set /a FileCount+=1
echo f=[%%a] fz=[%%~za]
set /a FileSizeB+=%%~za
set /a FileSizeKB+=!FileSizeB! / 1024
set /a FileSizeB=!FileSizeB! %% 1024
set /a FileSizeMB+=!FileSizeKB! / 1024
set /a FileSizeKB=!FileSizeKB! %% 1024
set /a FileSizeGB+=!FileSizeMB! / 1024
set /a FileSizeMB=!FileSizeMB! %% 1024
))>output.txt
Without looking at the output text file I can't tell....
It runs fine with everything I throw at it. Basically, if the folder does not exist the batch file will exit so we can assume the folder does exist. there are obviously files that are being processed and as far as the code goes, for each file it encounters it should be able to return it's size and filename... so for some reason, something is not right somewhere and I do not suspect the code itself.
you didn't confirm what your operating system is.
On the third line, can you change it to c:\windows\temp and see what happens.
Also, it would be helpful for me to actually see the output file because I need to identify which files, and why, some square brackets are blank. I will be in a better position to help you once I see the results for myself.
Your screen images do not give any clues. You have blanked out certain information which might have been helpful.
Business Accounts
Answer for Membership
by: QlemoPosted on 2009-03-30 at 07:33:37ID: 24019313
The following line
robocopy /njh /l /is . . /S /nfl /ndl
will give you a list like (which can be processed further if you request):
Select allOpen in new window