The operating system is WinXP. I want to realize the function of displaying the remaining disk space without using third-party software. I've been lurking for several days and wrote the following code. Please help me.
@echo off
rem There are problems
rem
rem 1、How to convert the number of bytes into a number in MB unit?
rem
rem 2、How to not generate temporary files?
color 1f
title Display remaining space on drive C
del size.txt>nul 2>nul
dir /-c c:\|find "Available bytes">size.txt
for /f "tokens=3" %%a in (size.txt) do echo There is %%a bytes of remaining space on drive C
del size.txt>nul 2>nul
echo.
echo.
echo.
echo Press any key to exit
pause>nul
Now a perfect solution has been found. Please see the code:
Source: Find the exact value of the remaining space of all partitions (in MB unit)
[ Last edited by namejm on 2007-3-11 at 02:26 PM ]
@echo off
rem There are problems
rem
rem 1、How to convert the number of bytes into a number in MB unit?
rem
rem 2、How to not generate temporary files?
color 1f
title Display remaining space on drive C
del size.txt>nul 2>nul
dir /-c c:\|find "Available bytes">size.txt
for /f "tokens=3" %%a in (size.txt) do echo There is %%a bytes of remaining space on drive C
del size.txt>nul 2>nul
echo.
echo.
echo.
echo Press any key to exit
pause>nul
Now a perfect solution has been found. Please see the code:
@echo off
setlocal enabledelayedexpansion
:Main
cls
set /a num2=1024*1024
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist %%i:\ (
set num3_str=
set num4=
for /f "tokens=3" %%j in ('dir /-c %%i:\') do set num1=%%j
if not "!num1!"=="0" (
call :loop
for /f "delims=0 tokens=*" %%k in ("!num3_str!") do set num3_str=%%k
echo.
echo The remaining space on drive %%i is !num3_str! MB
echo.
)
)
)
)
pause
goto Main
:loop
:: Find quotient
set /a num3=%num4%%num1:~0,1%/%num2%
:: Quotient sequence
set num3_str=%num3_str%%num3%
:: Find remainder
set /a num4=%num4%%num1:~0,1%%%%num2%
if %num4% equ 0 set num4=
set num1=%num1:~1%
if not "%num1%"=="" goto loop
goto :eof
Source: Find the exact value of the remaining space of all partitions (in MB unit)
[ Last edited by namejm on 2007-3-11 at 02:26 PM ]

DigestI