When working with files on Windows, it's often useful to quickly obtain information about their size, especially when dealing with storage constraints or data management tasks. Knowing the precise size of a file in bytes becomes particularly critical in scenarios where storage optimization is important, or when making informed decisions about data transfers and backups. This tutorial provides 2 methods how to get file size in bytes on Windows.
Method 1 - CMD
Open Command Prompt (CMD) and run the following command to retrieve file size in bytes:
for %I in ("test.txt") do @echo %~zI
This command uses the
for loop to iterate over the specified file and prints its size in bytes. The
%~zI syntax extracts the size information.
Method 2 - PowerShell
PowerShell, a more advanced scripting environment, offers a concise method to retrieve file size. Open PowerShell and execute the following command:
The command uses the
Get-Item cmdlet to obtain file information, and
Length is then used to retrieve the size in bytes.