I'm trying to find the size a particular folder say 'log' inside my current directory. please suggest me the batch commands used only to retrieve the size of the 'log' folder.
Asked
Active
Viewed 88 times
0
-
Related: [Folder list and its sizes](http://stackoverflow.com/a/37190069). – aschipfl Sep 26 '16 at 10:28
3 Answers
0
i suggesting one window command it display recursively all file size and last line show total size of folder
"dir /S log"

Hardik
- 1,519
- 1
- 10
- 10
0
@echo off
for /f "tokens=2 delims=," %%a in ('dir /s /-c log\^|findstr /b /c:" "') do (
for /f "tokens=1" %%b in ("%%a") do set x=%%b& goto :done
)
:done
echo %x% Bytes in this folder (and subfolders)
Token(s) might be needed to be adapted to local language.

Stephan
- 53,940
- 10
- 58
- 91
-
I'd add the `/-C` option to `dir` so there is no more need to remove (locale-dependent) thousand separators explicitly... – aschipfl Sep 26 '16 at 10:30
-
0
You can try this (Batch/Vbscript) file :
@echo off
Title Get Size of Folder and its subfolders
set "Folder=C:\log"
Set Log=Folder_Size.txt
(
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
)> "%Log%"
For /f "delims=" %%a in ('Dir "%Folder%" /AD /b /s') do (
(
echo The size of "%%a" is
Call :GetSize "%%a"
)>> "%Log%"
)
start "" "%Log%"
::***********************************************************************
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo Set fso = CreateObject("Scripting.FileSystemObject"^)
echo Set objFolder= fso.GetFolder(MyFolder^)
echo GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo For i = 0 to 4
echo If iSize ^> 1024 Then
echo iSize = iSize / 1024
echo Else
echo Exit For
echo End If
echo Next
echo FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b
::***********************************************************************
Edit : On 27/09/2016 Just for one folder and no recursive :
@echo off
mode con cols=67 lines=5 & Color 0A
Title Get Size of Folder and its subfolders
set "Folder=C:\HackooTest"
Set Log=%Folder%_Size.txt
(
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
)> "%Log%"
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
pause & Start "" "%Log%"
exit
::***********************************************************************
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo Set fso = CreateObject("Scripting.FileSystemObject"^)
echo Set objFolder= fso.GetFolder(MyFolder^)
echo GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo For i = 0 to 4
echo If iSize ^> 1024 Then
echo iSize = iSize / 1024
echo Else
echo Exit For
echo End If
echo Next
echo FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b
::***********************************************************************

Hackoo
- 18,337
- 3
- 40
- 70
-
Many thanks for your suggestion. Here i'm getting the size of all individual folders and sub folders inside log folder. My actual requirement is to get a single word output where it displays the log folder size as a whole only. Can you give a suggestion here? – Joey Sep 27 '16 at 09:54
-
with the last edit code i get this below: it shows the hardcoded string 'The size of path/folder is ' but not the size value. – Joey Oct 03 '16 at 08:16