185

Is it possible in Windows to get a folder's size from the command line without using any 3rd party tool?

I want the same result as you would get when right clicking the folder in the windows explorer → properties.

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78

22 Answers22

159

There is a built-in Windows tool for that:

dir /s 'FolderName'

This will print a lot of unnecessary information but the end will be the folder size like this:

 Total Files Listed:
       12468 File(s)    182,236,556 bytes

If you need to include hidden folders add /a.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Nir Duan
  • 6,164
  • 4
  • 24
  • 38
157

You can just add up sizes recursively (the following is a batch file):

@echo off
set size=0
for /r %%x in (folder\*) do set /a size+=%%~zx
echo %size% Bytes

However, this has several problems because cmd is limited to 32-bit signed integer arithmetic. So it will get sizes above 2 GiB wrong1. Furthermore it will likely count symlinks and junctions multiple times so it's at best an upper bound, not the true size (you'll have that problem with any tool, though).

An alternative is PowerShell:

Get-ChildItem -Recurse | Measure-Object -Sum Length

or shorter:

ls -r | measure -sum Length

If you want it prettier:

switch((ls -r|measure -sum Length).Sum) {
  {$_ -gt 1GB} {
    '{0:0.0} GiB' -f ($_/1GB)
    break
  }
  {$_ -gt 1MB} {
    '{0:0.0} MiB' -f ($_/1MB)
    break
  }
  {$_ -gt 1KB} {
    '{0:0.0} KiB' -f ($_/1KB)
    break
  }
  default { "$_ bytes" }
}

You can use this directly from cmd:

powershell -noprofile -command "ls -r|measure -sum Length"

1 I do have a partially-finished bignum library in batch files somewhere which at least gets arbitrary-precision integer addition right. I should really release it, I guess :-)

kaartic
  • 523
  • 6
  • 24
Joey
  • 344,408
  • 85
  • 689
  • 683
  • 2
    Steve, in my eyes PowerShell is way more Unix-y than Unix in that most core commands are really orthogonal. In Unix `du` gives directory size but all it's doing is walking the tree and summing up. Something that can be very elegantly expressed in a pipeline like here :-). So for PowerShell I usually look for how you can decompose the high-level goal into suitable lower-level operations. – Joey Oct 10 '12 at 08:13
  • It does not seem to return the current result for the home directory of a user. In one case, if I right click on a home folder and get properties, I see ~200 MB. If I do ls -r | measure -s length then I see 6 megs (in bytes) – garg Aug 05 '13 at 16:00
  • 3
    I see, it seems to ignore hidden folders that way. ls -force -r works if I want to include hidden folders as well. – garg Aug 05 '13 at 16:12
  • For reference, the Sysinternals du (per Steve's answer) is smart enough not to iterate into junction points, etc., and even handles hardlinks properly. – Harry Johnston Sep 27 '14 at 23:37
  • 2
    `folder\*` is not working for me the size of the folder that i put in the place shows 0 bytes, Is there any solution? – IT researcher Jul 22 '15 at 07:01
  • @ITresearcher I'm also getting 0 as well. I tried `powershell -noprofile -command "ls -r|measure -s Length"` and works fine – Linga Mar 14 '16 at 06:41
  • 2
    A slightly better looking version: powershell -noprofile -command "'{0:N0}' -f (ls -r|measure -s Length).Sum" – zumalifeguard Mar 25 '16 at 19:05
  • is there a way to add a command line parameter for the folder? – athos Jan 29 '18 at 01:38
  • 1
    @athos: Use `%1` in place of `folder` in the batch file, or add a parameter to the PowerShell script and add that as an argument to `Get-ChildItem`. But perhaps such things are better asked as a separate question if you have trouble with that part (as it has no relation to the original question here). – Joey Jan 29 '18 at 14:30
  • 1
    just for those who might enter, these are the ways to query a folder: in powerscript: `Get-ChildItem -Path c:\temp -Recurse | Measure-Object -Sum Length`, in `cmd`: `powershell -noprofile -command "'{0:N0}' -f (ls c:\temp -r|measure -s Length).Sum"` – athos Jan 29 '18 at 23:42
  • It will quit with error on first directory with no access. It should skip it, or give only warning. – Sylwester Zarębski Apr 10 '19 at 06:30
  • I found I was hitting a bunch of errors with very deep file structures, and then learned of Windows `260` char path limit. Changing registry to allow long file paths fixed this for me. https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/ – Intrastellar Explorer Nov 03 '19 at 21:36
  • 1
    @ITresearcher The format of the `for` command is incorrect, it should be this: `for /r folder %%x in (*) do set /a size+=%%~zx` – Serge N Oct 28 '20 at 07:51
128

Oneliner:

powershell -command "$fso = new-object -com Scripting.FileSystemObject; gci -Directory | select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName | sort Size -Descending | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName"

Same but Powershell only:

$fso = new-object -com Scripting.FileSystemObject
gci -Directory `
  | select @{l='Size'; e={$fso.GetFolder($_.FullName).Size}},FullName `
  | sort Size -Descending `
  | ft @{l='Size [MB]'; e={'{0:N2}    ' -f ($_.Size / 1MB)}},FullName

This should produce the following result:

Size [MB]  FullName
---------  --------
580,08     C:\my\Tools\mongo
434,65     C:\my\Tools\Cmder
421,64     C:\my\Tools\mingw64
247,10     C:\my\Tools\dotnet-rc4
218,12     C:\my\Tools\ResharperCLT
200,44     C:\my\Tools\git
156,07     C:\my\Tools\dotnet
140,67     C:\my\Tools\vscode
97,33      C:\my\Tools\apache-jmeter-3.1
54,39      C:\my\Tools\mongoadmin
47,89      C:\my\Tools\Python27
35,22      C:\my\Tools\robomongo
frizik
  • 1,766
  • 1
  • 13
  • 17
  • 2
    Is there a way to show all the files and size in Mb in the base folder as well? In this case `C:\my\Tools\` – Raunak Thomas Jun 29 '18 at 05:35
  • 2
    Plus it breaks when there are lots of folders (For example in the C: drive) – Raunak Thomas Jun 29 '18 at 06:00
  • 4
    `0.00 C:\Windows` can I optimize this for all folder, tried already run as admin – Tilo Feb 06 '19 at 23:05
  • this is good but it truncates my component folder names. what is the command to display them entirely? – sean.net Aug 09 '19 at 14:24
  • @sean.net do you mean it ends with "..." in case of long folders? That's how `ft` (`Format-Table`) works. You can try `fl` instead (`Format-List`) – frizik Aug 16 '19 at 18:52
71

I suggest to download utility DU from the Sysinternals Suite provided by Microsoft at this link http://technet.microsoft.com/en-us/sysinternals/bb896651

usage: du [-c] [-l <levels> | -n | -v] [-u] [-q] <directory>
   -c     Print output as CSV.
   -l     Specify subdirectory depth of information (default is all levels).
   -n     Do not recurse.
   -q     Quiet (no banner).
   -u     Count each instance of a hardlinked file.
   -v     Show size (in KB) of intermediate directories.


C:\SysInternals>du -n d:\temp

Du v1.4 - report directory disk usage
Copyright (C) 2005-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

Files:        26
Directories:  14
Size:         28.873.005 bytes
Size on disk: 29.024.256 bytes

While you are at it, take a look at the other utilities. They are a life-saver for every Windows Professional

Steve
  • 213,761
  • 22
  • 232
  • 286
  • 19
    That's hardly "without any 3rd-party tool", I guess. – Joey Oct 10 '12 at 07:18
  • 13
    Oh right, but it thought that family should not be considered '3rd party'. – Steve Oct 10 '12 at 07:45
  • 2
    Well, granted, but it's still an additional download (or using `\\live.sysinternals.com` if that still exists). I wholeheartedly agree though, that all the sysinternals tools should be included by default. Although for many uses PowerShell is a quite worthy replacement. – Joey Oct 10 '12 at 07:54
  • 1
    Did someone say Powershell? Try the following: "{0:N2}" -f ((Get-ChildItem C:\Temp -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB) + " MB" – John Homer Mar 11 '13 at 15:52
  • This utility (v1.61) has a permission problem resulting in the size of some files not being included. This makes the tool somewhat unreliable unless using an admin elevated console. _NOTE: Files and sizes **are** listed with `dir` command._ (I had thought it might be a file size issue due to the problem directory containing database files with many of them > 2GB.) – Disillusioned May 09 '18 at 06:07
21

If you have git installed in your computer (getting more and more common) just open MINGW32 and type: du folder

Custodio
  • 8,594
  • 15
  • 80
  • 115
  • 7
    You can use the following command `du -h -d 1 folder | sort -h` if you want human readable size, one level of subdirectories only, and sort by size. – vard Feb 07 '19 at 16:21
11

Here comes a powershell code I write to list size and file count for all folders under current directory. Feel free to re-use or modify per your need.

$FolderList = Get-ChildItem -Directory
foreach ($folder in $FolderList)
{
    set-location $folder.FullName
    $size = Get-ChildItem -Recurse | Measure-Object -Sum Length
    $info = $folder.FullName + "    FileCount: " + $size.Count.ToString() + "   Size: " + [math]::Round(($size.Sum / 1GB),4).ToString() + " GB"
    write-host $info
}
Ryan Lee
  • 111
  • 1
  • 2
  • Works for me. Useful if your on a headless server. – andrew pate Dec 26 '18 at 12:22
  • Simple and elegant! My version: `$FolderList = Get-ChildItem -Directory -Force; $data = foreach ($folder in $FolderList) { set-location $folder.FullName; $size = Get-ChildItem -Recurse -Force | Measure-Object -Sum Length; $size | select @{n="Path"; e={$folder.Fullname}}, @{n="FileCount"; e={$_.count}}, @{n="Size"; e={$_.Sum}} }` This will provide objects (more Powershell-ish), 'FileCount' and 'Size' are integers (so you can process them later, if needed), and 'Size' is in bytes, but you could easily convert it to GB (or the unit you want) with `$Data.Size / 1GB`. – curropar Oct 14 '19 at 09:47
  • Or a one-liner: `$Data = dir -Directory -Force | %{ $CurrentPath = $_.FullName; Get-ChildItem $CurrentPath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Sum Length | select @{n="Path"; e={$CurrentPath}}, @{n="FileCount"; e={$_.count}}, @{n="Size"; e={$_.Sum}} }` – curropar Oct 14 '19 at 09:50
  • I like this one best, but isn't the `set-location` unnecessary? You can just go `Get-ChildItem $folder.FullName`, that way you come out the other side without the current directory changing underneath you. – BenderBoy Aug 12 '20 at 17:26
  • 1
    Thanks @BenderBoy. It's better to remove `set-location` and use `Get-ChildItem $folder.FullName` directly. – Ryan Lee Aug 14 '20 at 08:11
10

I recommend using https://github.com/aleksaan/diskusage utility which I wrote. Very simple and helpful. And very fast.

Just type in a command shell

diskusage.exe -path 'd:/go; d:/Books'

and get list of folders arranged by size

  1.| DIR: d:/go      | SIZE: 325.72 Mb   | DEPTH: 1 
  2.| DIR: d:/Books   | SIZE:  14.01 Mb   | DEPTH: 1 

This example was executed at 272ms on HDD.

You can increase depth of subfolders to analyze, for example:

diskusage.exe -path 'd:/go; d:/Books' -depth 2

and get sizes not only for selected folders but also for its subfolders

  1.| DIR: d:/go            | SIZE: 325.72 Mb   | DEPTH: 1 
  2.| DIR: d:/go/pkg        | SIZE: 212.88 Mb   | DEPTH: 2 
  3.| DIR: d:/go/src        | SIZE:  62.57 Mb   | DEPTH: 2 
  4.| DIR: d:/go/bin        | SIZE:  30.44 Mb   | DEPTH: 2 
  5.| DIR: d:/Books/Chess   | SIZE:  14.01 Mb   | DEPTH: 2 
  6.| DIR: d:/Books         | SIZE:  14.01 Mb   | DEPTH: 1 
  7.| DIR: d:/go/api        | SIZE:   6.41 Mb   | DEPTH: 2 
  8.| DIR: d:/go/test       | SIZE:   5.11 Mb   | DEPTH: 2 
  9.| DIR: d:/go/doc        | SIZE:   4.00 Mb   | DEPTH: 2 
 10.| DIR: d:/go/misc       | SIZE:   3.82 Mb   | DEPTH: 2 
 11.| DIR: d:/go/lib        | SIZE: 358.25 Kb   | DEPTH: 2 

*** 3.5Tb on the server has been scanned for 3m12s**

Ro Yo Mi
  • 14,790
  • 5
  • 35
  • 43
3

I guess this would only work if the directory is fairly static and its contents don't change between the execution of the two dir commands. Maybe a way to combine this into one command to avoid that, but this worked for my purpose (I didn't want the full listing; just the summary).

GetDirSummary.bat Script:

@echo off
rem  get total number of lines from dir output
FOR /F "delims=" %%i IN ('dir /S %1 ^| find "asdfasdfasdf" /C /V') DO set lineCount=%%i
rem  dir summary is always last 3 lines; calculate starting line of summary info
set /a summaryStart="lineCount-3"
rem  now output just the last 3 lines
dir /S %1 | more +%summaryStart%

Usage:

GetDirSummary.bat c:\temp

Output:

 Total Files Listed:
          22 File(s)         63,600 bytes
           8 Dir(s)  104,350,330,880 bytes free
Steve
  • 31
  • 5
  • This is actually the reply that needed. No external tools, no need to execute PowerShell (that will trigger some alarms and will definitely be slow). THANKS! – DefToneR Aug 01 '22 at 16:48
2

This code is tested. You can check it again.

@ECHO OFF
CLS
SETLOCAL
::Get a number of lines contain "File(s)" to a mytmp file in TEMP location.
DIR /S /-C | FIND "bytes" | FIND /V "free" | FIND /C "File(s)" >%TEMP%\mytmp
SET /P nline=<%TEMP%\mytmp
SET nline=[%nline%]
::-------------------------------------
DIR /S /-C | FIND "bytes" | FIND /V "free" | FIND /N "File(s)" | FIND "%nline%" >%TEMP%\mytmp1
SET /P mainline=<%TEMP%\mytmp1
CALL SET size=%mainline:~29,15%
ECHO %size%
ENDLOCAL
PAUSE
Chienvela
  • 21
  • 1
  • Thanks, it works for me with folders which smaller than 1GB, but for example, I have a folder of 3,976,317,115 bytes (3.70GB), and the script return to me this string ") 932", do you know why? – elady Jan 16 '14 at 08:20
2

Try:

SET FOLDERSIZE=0
FOR /F "tokens=3" %A IN ('DIR "C:\Program Files" /a /-c /s ^| FINDSTR /C:" bytes" ^| FINDSTR /V /C:" bytes free"') DO SET FOLDERSIZE=%A

Change C:\Program Files to whatever folder you want and change %A to %%A if using in a batch file

It returns the size of the whole folder, including subfolders and hidden and system files, and works with folders over 2GB

It does write to the screen, so you'll have to use an interim file if you don't want that.

FrinkTheBrave
  • 3,894
  • 10
  • 46
  • 55
2

The following one-liners can be used to determine the size of a folder.

The post is in Github Actions format, indicating which type of shell is used.

shell: pwsh
run: |
  Get-ChildItem -Path C:\temp -Recurse | Measure-Object -Sum Length


shell: cmd
run: |
  powershell -noprofile -command "'{0:N0}' -f (ls C:\temp -r | measure -s Length).Sum"
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
2

Open windows CMD and run follow command

dir /s c:\windows
Tuan Le Anh
  • 147
  • 7
  • 1
    this gives the size of every file - it's still spinning after 5 minutes when the powershell script gave me the totals in about 2 seconds –  May 03 '22 at 05:41
  • 1
    `dir /s > dirstat.txt` creates a file for you to look at and completes pretty much instantly – Dylan Musil Nov 09 '22 at 22:02
1

I think your only option will be diruse (a highly supported 3rd party solution):

Get file/directory size from command line

The Windows CLI is unfortuntely quite restrictive, you could alternatively install Cygwin which is a dream to use compared to cmd. That would give you access to the ported Unix tool du which is the basis of diruse on windows.

Sorry I wasn't able to answer your questions directly with a command you can run on the native cli.

Illizian
  • 484
  • 1
  • 5
  • 13
  • 1
    If you just need `du` then Cygwin is way overkill. Just go with [GnuWin32](http://gnuwin32.sourceforge.net/). – Joey Oct 10 '12 at 07:55
  • 2
    Indeed it is overkill, but it's also awesome. +1 for your post above @joey (haven't got the rep to do it literally :( ) – Illizian Oct 10 '12 at 08:05
  • In my humble opinion Cygwin may be useful to some but it's far from awesome and rather horrible. But I guess Unix users say the same about Wine. – Joey Oct 10 '12 at 08:14
  • 1
    "wine" - shudder, I use Cygwin on my development laptop because the battery life is appalling under linux and it's not convenient to run a VM on it. It takes some setting up, but Cygwin is brilliant for those among us who miss the nix shell in Windows, personally I don't like Powershell I may have to check GnuWin out though. Thanks @Joey. – Illizian Oct 10 '12 at 08:25
1

I got du.exe with my git distribution. Another place might be aforementioned Microsoft or Unxutils.

Once you got du.exe in your path. Here's your fileSizes.bat :-)

@echo ___________
@echo DIRECTORIES
@for /D %%i in (*) do @CALL du.exe -hs "%%i"
@echo _____
@echo FILES
@for %%i in (*) do @CALL du.exe -hs "%%i"
@echo _____
@echo TOTAL
@du.exe -sh "%CD%"

___________
DIRECTORIES
37M     Alps-images
12M     testfolder
_____
FILES
765K    Dobbiaco.jpg
1.0K    testfile.txt
_____
TOTAL
58M    D:\pictures\sample
Frank N
  • 9,625
  • 4
  • 80
  • 110
1

::Get a number of lines that Dir commands returns (/-c to eliminate number separators: . ,) ["Tokens = 3" to look only at the third column of each line in Dir]

FOR /F "tokens=3" %%a IN ('dir /-c "%folderpath%"') DO set /a i=!i!+1

Number of the penultimate line, where is the number of bytes of the sum of files:

set /a line=%i%-1

Finally get the number of bytes in the penultimate line - 3rd column:

set i=0
FOR /F "tokens=3" %%a IN ('dir /-c "%folderpath%"') DO (
  set /a i=!i!+1
  set bytes=%%a
  If !i!==%line% goto :size  
)
:size
echo %bytes%

As it does not use word search it would not have language problems.

Limitations:

  • Works only with folders of less than 2 GB (cmd does not handle numbers of more than 32 bits)
  • Does not read the number of bytes of the internal folders.
1

The following script can be used to fetch and accumulate the size of each file under a given folder.
The folder path %folder% can be given as an argument to this script (%1).
Ultimately, the results is held in the parameter %filesize%

@echo off
SET count=1
SET foldersize=0
FOR /f "tokens=*" %%F IN ('dir /s/b %folder%') DO (call :calcAccSize "%%F")
echo %filesize%
GOTO :eof

:calcAccSize
 REM echo %count%:%1
 REM set /a count+=1
 set /a foldersize+=%~z1
 GOTO :eof

Note: The method calcAccSize can also print the content of the folder (commented in the example above)

Lior Kirshner
  • 696
  • 5
  • 9
1

So here is a solution for both your requests in the manner you originally asked for. It will give human readability filesize without the filesize limits everyone is experiencing. Compatible with Win Vista or newer. XP only available if Robocopy is installed. Just drop a folder on this batch file or use the better method mentioned below.

@echo off
setlocal enabledelayedexpansion
set "vSearch=Files :"

For %%i in (%*) do (
    set "vSearch=Files :"
    For /l %%M in (1,1,2) do ( 
        for /f "usebackq tokens=3,4 delims= " %%A in (`Robocopy "%%i" "%%i" /E /L /NP /NDL /NFL ^| find "!vSearch!"`) do (
            if /i "%%M"=="1" (
                set "filecount=%%A"
                set "vSearch=Bytes :"
            ) else (
                set "foldersize=%%A%%B"
            )
        )
    )
    echo Folder: %%~nxi FileCount: !filecount! Foldersize: !foldersize!
    REM remove the word "REM" from line below to output to txt file
    REM echo Folder: %%~nxi FileCount: !filecount! Foldersize: !foldersize!>>Folder_FileCountandSize.txt
)
pause

To be able to use this batch file conveniently put it in your SendTo folder. This will allow you to right click a folder or selection of folders, click on the SendTo option, and then select this batch file.

To find the SendTo folder on your computer simplest way is to open up cmd then copy in this line as is.

explorer C:\Users\%username%\AppData\Roaming\Microsoft\Windows\SendTo

julesverne
  • 392
  • 1
  • 8
  • 18
  • For anyone worried Robocopy will move files.. don't. the /l option only lists. In addition, Robocopy is not 3rd party, Robocopy is installed in Windows by default from Vista up, XP you need to install it. – julesverne May 15 '19 at 05:30
  • Thanks for the addition. Glad to see this thread still attracting attention ;-) Might want to add how to install robocopy (great tool!). – Eldad Assis May 15 '19 at 10:17
  • I posted the original solution 4 years earlier [here on SO](https://stackoverflow.com/questions/30513287/faster-way-to-get-folder-size-with-batch-script/30536204). Using `robocopy ` by far is the fastest solution. – user1016274 Apr 29 '22 at 09:51
1

It's better to use du because it's simple and consistent.

install scoop: iwr -useb get.scoop.sh | iex

install busybox: scoop install busybox

get dir size: du -d 0 . -h

SodaCris
  • 358
  • 4
  • 7
1

I was at this page earlier today 4/27/22, and after trying DU by SysInternals (https://learn.microsoft.com/en-us/sysinternals/downloads/du) and piping the output etc etc. I said "Didn't I have to do this in VBscript? I got this to work for total size of ISOroot folder and all subfolders. Replace the Folder fullpath with your own. It's very fast.

GetFolderSize.vbs

 Dim fs, f, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder("C:\XPE\Custom\x64\IsoRoot")
    s = UCase(f.Name) & " uses " & f.size & " bytes."
    MsgBox s, 0, "Folder Size Info"

s=  FormatNumber(f.size/1024000,2) & " MB"
    MsgBox s, 0, "Folder Size Info"

s=  FormatNumber(f.size/1073741824,2) & " GB"
    MsgBox s, 0, "Folder Size Info"
Tony4219
  • 11
  • 3
1

Use Windows Robocopy.

Put this in a batch file:

@echo off
pushd "%~dp0"
set dir="C:\Temp"
for /f "tokens=3" %%i in ('robocopy /l /e /bytes %dir% %dir% ^| findstr Bytes') do @echo %%i
pause

Set the path for your folder in the dir variable.

The for loop gets the 3rd string using tokens=3, which is the size in bytes, from the robocopy findstr command.

The /l switch in robocopy only lists the output of the command, so it doesn't actually run.

The /e switch in robocopy copies subdirectories including empty ones.

The /bytes switch in robocopy copies subdirectories including empty ones.
You can omit the /bytes switch to get the size in default folder properties sizes (KB, MB, GB...)

The findstr | Bytes command finds the output of robocopy command which contains total folder size.

And finally echo the index %%i to the console.

If you need to save the folder size to a variable replace

do @echo %%i

with

set size=%%i

If you want to send the folder size to another program through clipboard:

echo %size% | clip

If you need to get the current folder size put the batch file into that folder and remove set dir="C:\Temp" and replace both %dir% with %cd%, which stands for current directory, like this:

@echo off
pushd "%~dp0"
for /f "tokens=3" %%i in ('robocopy /l /e /bytes "%cd%" "%cd%" ^| findstr Bytes') do @echo %%i
pause
0

I solved similar problem. Some of methods in this page are slow and some are problematic in multilanguage environment (all suppose english). I found simple workaround using vbscript in cmd. It is tested in W2012R2 and W7.

>%TEMP%\_SFSTMP$.VBS ECHO/Set objFSO = CreateObject("Scripting.FileSystemObject"):Set objFolder = objFSO.GetFolder(%1):WScript.Echo objFolder.Size
FOR /F %%? IN ('CSCRIPT //NOLOGO %TEMP%\_SFSTMP$.VBS') DO (SET "S_=%%?"&&(DEL %TEMP%\_SFSTMP$.VBS))

It set environment variable S_. You can, of course, change last line to directly display result to e.g.

FOR /F %%? IN ('CSCRIPT //NOLOGO %TEMP%\_SFSTMP$.VBS') DO (ECHO "Size of %1 is %%?"&&(DEL %TEMP%\_SFSTMP$.VBS))

You can use it as subroutine or as standlone cmd. Parameter is name of tested folder closed in quotes.

arpi
  • 1
  • 1
-4

Easiest method to get just the total size is powershell, but still is limited by fact that pathnames longer than 260 characters are not included in the total

ray
  • 3
  • 1