You can use the cmd command dir /s <folder>
to calculate folder size, but it generates too much irrelevant information. Filtering is possible, yet using dir /s <folder> | find 'string'
isn’t very universal. The outputs in English and Chinese differ in Windows 7, 10, 11, and server versions, making compatibility quite poor. Hence, I turn to PowerShell for a simpler and more convenient solution!
Below is a PowerShell command that can be used to calculate the size of a folder and its subfolders:
Two-Line Command
|
|
Please replace <folder path>
with the actual path of the folder you want to measure.
This command will recursively retrieve all files within the specified folder, calculate their total size, and output the total.
For example, to calculate the size of the folder C:\MyFolder
and its subfolders, you can run the following command:
|
|
After executing the command, you will see the total size of the folder C:\MyFolder
and its subfolders.
You can also convert the output size to megabytes (MB). Here’s the corresponding PowerShell command:
|
|
Again, please replace <folder path>
with the actual path of the folder.
This command first calculates the total size of all files in the specified folder and its subfolders. Then, it converts the size to megabytes (MB) and outputs the result.
For example, to display the size of the folder C:\MyFolder
and its subfolders in MB, you can run:
|
|
After executing the command, the output will look similar to:
123.45 MB
If you want to display the results in gigabytes (GB), simply replace all instances of MB with GB.
One-Line Command
You can condense the earlier PowerShell commands into a single line:
|
|
Please replace <folder path>
with the actual path of the folder you want to measure.
For example, to calculate the size of the folder C:\MyFolder
and its subfolders in a single line, you can run:
|
|
Executing this command will display the total size of the folder C:\MyFolder
and its subfolders.
Output in MB:
|
|
Please replace <folder path>
with the actual path of the folder.
For example, to show the size of the folder C:\MyFolder
and its subfolders in MB, you can run:
|
|
Output in GB:
|
|