Imagine you need to determine the size of a directory, but you do not have access to it and cannot change the permissions, either. Such a situation is common with Windows user profiles. This article shows how to deal with it.
Determine Folder Size
There are several ways to determine the size of a directory from the command line. But the possibly obvious choice, the command diruse.exe, cannot be used with user profiles – like many other tools it does not know how to handle the directory junctions in V2 profiles.
Of course, there is always the possibility of rolling your own, for example as a PowerShell script. But it is much easier (and also less error-prone) to resort to a proven tool like the Sysinternals interpretation of the popular Unix tool du. Usage is simple:
Directory Disk Usage, Diruse.exe: Displays information about a disk and the contents of its partition table. DiskMap, Diskmap.exe: Displays information about a disk and the contents of its partition table. Diskpart Command Line Utility, Diskpart.exe: Enables storage configuration from a script, remote session, or other command prompt. Websites, Resource Kits, Books and Utilities. Microsoft Security Response Center (MSRC) - Microsoft). Security Bulletins - Microsoft Security TechCenter. Microsoft Update Catalog - Search for specific updates by KB#.
There is only one problem with du: it cannot bypass security and count every file regardless of permissions. Basically you only see what you are allowed to see. Here is an interesting way around that limitation, using robocopy’s ability to list every file in backup mode: Do cheez its expire.
Diruse.exe
Do you know of other ways to calculate a directory’s size without having access to it? Let us know!
How to find the size of a file
In Windows, we can use dir command to get the file size.
But there is no option/switch to print only the file size.
Diruse.exe Windows 2008
Get size for all the files in a directory
Dir command accepts wild cards. We can use ‘*” to get the file sizes for all the files in a directory.
We can also get size for files of certain type. For example, to get file size for mp3 files, we can run the command ‘dir *.mp3‘.
The above command prints file modified time also. To print only the file name and size we can run the below command from a batch file.
Save the above commands to a text file, say filesize.bat, and run it from command prompt.
Get directory size
There’s no Windows built in command to find directory size. But there is a tool called diruse.exe which can be used to get folder size. This tool is part of XP support tools. This command can be used to get directory size. This command’s syntax is given below.
As you can see in the above example, diruse prints the directory size in bytes and it also prints the number of files in the directory(it counts the number of files in the sub folders also)
To get the directory size in mega bytes we can add /M switch.
Microsoft Diruse.exe
Though the tool is intended for XP and Server 2003, I have observed that it works on Windows 7 also. The above examples were indeed from a Windows 7 computer.