是否可以使用Batch / vbs为目录中的所有子文件夹添加foldersize到foldername?
实施例: 我在像
这样的目录中有很少的子文件夹Name --- Size
Folder1 --- (22.5GB)
Folder2 --- (980.3MB)
Folder3 --- (968.4KB)
需要将文件夹名称更改为,
Folder1 [22.5 GB]
Folder2 [980.3 MB]
Folder3 [968.4 KB]
我尝试使用以下代码,它在cmd面板中获取文件夹大小,但需要知道如何将大小添加到文件夹名称,
@echo off
Title Get Size of Folder and its subfolders
set "Folder=C:\RootFolder\"
For /f "delims=" %%a in ('Dir "%Folder%" /AD /b /s') do (
(
echo The size of "%%a" is
Call :GetSize "%%a"
)
)
For /D %%a in (*) do rename "%%a" "%%a [!GetSize!]"
pause
::*************************
: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
::*********************