1

If I run this command:

fsutil volume diskfree e:

I get:

Error: Access is denied.

Only by manually opening an "elevated" cmd.exe does it output the actual output of the command.

I need a (built-in) command which determines the free space of a given disk (drive letter), even if the cmd.exe is not "elevated" (administrator).

(The reason it requires elevation is apparently that "fsutil" can do a bunch of other things as well.)

2
  • dir e: will output the number of free bytes.
    – DavidPostill
    Commented Oct 15, 2020 at 19:20
  • Minor note: the system folder WinSxS contains symlinks (or similar) so those files are often counted multiple times by windows and this can cause a lower free-space count than is actually present. I don't think there is a work-around for this.
    – Yorik
    Commented Oct 15, 2020 at 21:42

3 Answers 3

1

This is along the same lines as @It Wasn't Me's answer

If you just want to see a quick output this is generally fastest:

DIR /AD/D E: | FIND /I " bytes free"

--[Result]--
               1 Dir(s)  28,616,892,416 bytes free

DIR /AD Will only return directories, /D is wide, meaning many entries are returned on each line. If you have a massive number of directories and only a few files change it to DIR /A-D/D

I don't see why you would need to get rid of the formatting of this output considering FSUtil offers a bunch of extra text and it wasn't mentioned in the question, also It includes the commas.

If you do want to remove the Commas as mention /-C will remove commas.

If you want the number out by itself to be used whether with or without commas the for /f loop becomes necessary, which @It Wasn't Me's has already covered well.

0

1. Use cmd internal command dir with /e and /-c to remove , from outputs

17 Dir(s)  21,489,500,160 bytes free

2. Using the 3rd token in for /f loop redirect to findstr /End filter where the line ends with "bytes" + [one character] + "free"

1º   2º                       *º
_| _____|  __________| __________*
17 Dir(s)  21489500160 bytes free  
tokens  =           |----------| is the same bytes.free to findstr

  • For command line:
for /f "tokens=3delims= " %i in ('dir E: /d /-c ^|findstr /e bytes.free')do @echo\%i

  • For bat file replace %i to %%i:
@echo off 

for /f "tokens=3delims= " %%i in ('dir E: /d /-c ^|findstr /e bytes.free')do echo\%%i

  • You can get some help from PowerShell to convert the free size to GB:
@echo off 

for /f "tokens=3delims= " %i in ('dir E: /d /-c ^|findstr /e bytes.free
')do Powershell -nop -c "$free=[math]::round(8357258532/1GB); Write-host $free'GB' -NoNewline
0

Instead of dir you can do this (since Vista IIRC) with wmic:

 wmic volume where driveletter="E:" get freespace
 wmic volume get driveletter,freespace | findstr E:

Or if you use Powershell, it can do the whole job without help:

 powershell -c write-host (get-volume -driveletter c).sizeremaining
 powershell -c write-host [math]::round((get-volume -driveletter c).sizeremaining/1GB)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .