我正在尝试查找特定文件夹在当前目录中说“日志”的大小。请建议我用于检索'log'文件夹大小的批处理命令。
答案 0 :(得分:0)
我建议一个窗口命令以递归方式显示所有文件大小,最后一行显示文件夹的总大小
" dir / S log"
答案 1 :(得分:0)
@echo off
for /f "tokens=2 delims=," %%a in ('dir /s /-c log\^|findstr /b /c:" "') do (
for /f "tokens=1" %%b in ("%%a") do set x=%%b& goto :done
)
:done
echo %x% Bytes in this folder (and subfolders)
可能需要使用令牌来适应当地语言。
答案 2 :(得分:0)
您可以尝试这个(Batch / Vbscript)文件:
@echo off
Title Get Size of Folder and its subfolders
set "Folder=C:\log"
Set Log=Folder_Size.txt
(
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
)> "%Log%"
For /f "delims=" %%a in ('Dir "%Folder%" /AD /b /s') do (
(
echo The size of "%%a" is
Call :GetSize "%%a"
)>> "%Log%"
)
start "" "%Log%"
::***********************************************************************
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo Set fso = CreateObject("Scripting.FileSystemObject"^)
echo Set objFolder= fso.GetFolder(MyFolder^)
echo GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo For i = 0 to 4
echo If iSize ^> 1024 Then
echo iSize = iSize / 1024
echo Else
echo Exit For
echo End If
echo Next
echo FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b
::***********************************************************************
编辑:2016年9月27日 仅针对一个文件夹而不是递归:
@echo off
mode con cols=67 lines=5 & Color 0A
Title Get Size of Folder and its subfolders
set "Folder=C:\HackooTest"
Set Log=%Folder%_Size.txt
(
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
)> "%Log%"
echo The size of "%Folder%" is
Call :GetSize "%Folder%"
pause & Start "" "%Log%"
exit
::***********************************************************************
:GetSize
(
echo wscript.echo GetSize("%~1"^)
echo Function GetSize(MyFolder^)
echo Set fso = CreateObject("Scripting.FileSystemObject"^)
echo Set objFolder= fso.GetFolder(MyFolder^)
echo GetSize = FormatSize(objFolder.Size^)
echo End Function
echo '*******************************************************************
echo 'Function to format a number into typical size scales
echo Function FormatSize(iSize^)
echo aLabel = Array("bytes", "KB", "MB", "GB", "TB"^)
echo For i = 0 to 4
echo If iSize ^> 1024 Then
echo iSize = iSize / 1024
echo Else
echo Exit For
echo End If
echo Next
echo FormatSize = Round(iSize,2^) ^& " " ^& aLabel(i^)
echo End Function
echo '*******************************************************************
)>%tmp%\Size.vbs
Cscript /NoLogo %tmp%\Size.vbs
Del %tmp%\Size.vbs
Exit /b
::***********************************************************************