English 中文(简体)
我如何找到驾车上所使用的空间,我是如何把它仅仅作为数量输出的?
原标题:How do I find the space used on a drive and how do I output it as just a number?

I am currently making a script for backing up my system, and I want to display the amount of used bytes on the system to list an "all" option as a complete backup. However, I can t seem to find how to output this as just a number in my script.

我先使用<代码>fsutil volume 软磁盘:,给我免费磁盘的号码,但我不知道如何进行,只能将其列为我的发言稿中的若干份。 我是否还需要使用什么? 甚至还有办法这样做?

问题回答

Why use fsutil.exe which generally requires elevated privileges, when you can do it using the built in dir command?

@For /F "Tokens=1,* EOL=[ Delims=)" %%G In ( Dir %SystemDrive% /W /-C ) Do @For /F %%I In ("%%H") Do @Set "FreeSpace=%%I"
@Echo %FreeSpace%

您也可以使用<条码>W.exe执行任务,无需升级:

@For /F "Tokens=1,* Delims==" %%G In ( %SystemRoot%System32wbemWMIC.exe Volume Where "DriveLetter= %SystemDrive% " Get FreeSpace /Value 2^>NUL ) Do @For /F %%I In ("%%H") Do @Set "FreeSpace=%%I"
@Echo(%FreeSpace%

You could even get the assistance of powershell.exe, once again without elevation:

@For /F %%G In ( %SystemRoot%System32WindowsPowerShellv1.0powershell.exe -NoProfile -Command "(Get-Volume -DriveLetter  %SystemDrive:~,1% ).SizeRemaining" 2^>NUL ) Do @Set FreeSpace=%%G"
@Echo(%FreeSpace%

如果你仍然希望使用你提议的<代码>fsutil.exe的指挥效用做同样的事,那么以下几句可能就足够了:

@Set "FreeSpace=" & For /F "Tokens=1,* Delims=:" %%G In ( %SystemRoot%System32fsutil.exe Volume DiskFree %SystemDrive% 2^>NUL ) Do @For /F %%I In ("%%H") Do @If Not Defined FreeSpace Set "FreeSpace=%%I"
@Echo(%FreeSpace:,=%




相关问题
complex batch replacement linux

I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...

How to split a string by spaces in a Windows batch file?

Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

热门标签