Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having 6 files in Inbound location : File names are like this -

LS_PRSAHD_XXXX.txt
LS_PRSAHD_XXXX.txt
LS_PRSADT_XXXX.txt
LS_PRSADT_XXXX.txt
LS_PRSATD_XXXX.txt
LS_PRSATD_XXXX.txt

I want to have the size of total 6 files thorugh batch file. So far I tried the below
for /f %%i in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSAHD_*.txt" ^| find /c /v ""') do @call set fileSizeHD=%%~zi

for /f %%j in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSADT_*.txt" ^| find /c /v ""') do @call set filesizeDT=%%~zj

for /f %%k in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSATD_*.txt" ^| find /c /v ""') do @call set filesizeTD=%%~zk


set /a Total=%fileSizeHD%+%fileSizeDT%+%fileSizeTD%

set /a KB=(%Total%/1024)+1
echo %KB%
set size="Websales File Size: %KB% KB"
echo File Size : %size% >>%logfile%


But This is taking only one set of LS_PRSAHD,DT and TD file but in the directory I have multiple HD,DT and TD files. I want to calculate the total size of all the files in the location. How to do it
Posted
Updated 10-Aug-14 10:05am
v2
Comments
Sergey Alexandrovich Kryukov 10-Aug-14 13:48pm    
Why relying too much on batch files? They are quite archaic. Their main value is: they always work, but you cannot do all with them.
—SA

1 solution

I don't think I would implement this as a BAT file solution for any of my clients but here is a batch file that works.

REM Zero out any previous values
set /a fileSizeHD=0
set /a fileSizeDT=0
set /a fileSizeTD=0
REM Sum up file sizes for selected files
for /f %%i in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSAHD_*.txt"') do set /a fileSizeHD=%%~zi + fileSizeHD
for /f %%j in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSADT_*.txt"') do set /a filesizeDT=%%~zj + fileSizeDT
for /f %%k in ('dir /b /a-d "\\LOC\INBOUND\LS_PRSATD_*.txt"') do set /a filesizeTD=%%~zk + filesizeTD
REM Compute Total KB Value
set /a Total=%fileSizeHD%+%fileSizeDT%+%fileSizeTD%
set /a KB=(%Total%/1024)+1
echo %KB%
set size="Websales File Size: %KB% KB"
echo File Size : %size% >>%logfile%
 
Share this answer
 
v2
Comments
DEbopm 10-Aug-14 16:11pm    
all sizes are coming as 0 kb
Mike Meinz 10-Aug-14 19:26pm    
Works fine on my Windows 8.1 PC.
[no name] 10-Aug-14 20:19pm    
Works for me Win7 also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900