You can use this VBscript to get folder size, but it will be in bytes:
Code: Select all
dim oFS, oFolder
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder("D:\folder_name")
wscript.echo oFolder.Name & " : " & round(oFolder.Size,2)
Change :
oFolder.Size
to :
oFolder.Size/1024/1024/1024
to get the size in GB
sourceEdited:I was able to modify it to output The result to an external file, in this form:
Folder_Name:Size_in_GB
This is the modified VBscript:
Code: Select all
dim oFS, oFolder, objShell
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("wscript.shell")
Set fsHandle = oFS.OpenTextFile ("D:\OutPut.txt",8,True)
set oFolder = oFS.GetFolder("D:\Folder_Name")
fsHandle.Writeline oFolder.Name & " : " & round(oFolder.Size/1024/1024/1024,2)
and this is the batch, it should give you all the size of all folders one after the other:
Code: Select all
@Echo OFF
:: Set Outfile and Folders Names
SET "OutFile=D:\out.txt"
SET "Folders=D:\folder_1 D:\Folder_2 D:\Folder_3"
:: Delete Old Results
IF Exist "%OutFile%" Del /Q "%OutFile%"
:: Get Size of All Folders
For %%a In (%Folders%) Do (
Call :size "%%a" "%OutFile%"
)
:: Display Each Folder with it's Size in GB
For /F "tokens=1,2 delims=:" %%A In ('TYPE "%OutFile%"') Do (
Echo Folder Name: %%A
Echo Folder Size:%%B GB
Echo.
)
pause
Exit /B
:size <Folder_Name> <Output_File_Path>
(
echo.dim oFS, oFolder, objShell
echo.set oFS = WScript.CreateObject^("Scripting.FileSystemObject"^)
echo.Set objShell = CreateObject^("wscript.shell"^)
echo.Set fsHandle = oFS.OpenTextFile ^("%~2",8,True^)
echo.set oFolder = oFS.GetFolder^("%~1"^)
echo.fsHandle.Writeline oFolder.Name ^& " : " ^& round^(oFolder.Size/1024/1024/1024,2^)
)>"%temp%\size.vbs"
"%temp%\size.vbs"
Change The "
OutFile" Variable to the destination where the size will be written to.
Change The "
Folders" Variable to the names of each folder seprated by a "
SPACE" (
folder names can't have spaces in it )