Windows command line window size

Get File size and directory size from command line

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.

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.

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.

Jan-18-2012
I validated/downloaded/started to install.
The setup software said, “This program has known compatibility issues.”
(I will probably continue anyway, in hopes that SOME of the software may work.)
I’m guessing that the problem is that I am running Windows 7 64-Bit.
Am I correct, that YOU are using Windows 7 32Bit ?

Jan-18-2012—followup
The attempt to instal; anyway, (in spite of compatibility problem) aborted,
It said, approximately, “can only be installed on WinXP”.

Try extracting the files instead of installing them. Command for this is something like this.
installer.exe /x

My machine is also 64 bit and is running on 64-bit OS.

In Windows7, right-click on the installer, select Troubleshoot compatibility, select Troubleshoot program, select first option “This program worked in earlier versions of Windows but won’t install or run now”, select Windows XP (Service Pack 2), select Start the program, ignore the compatibility issue warning by clicking Run program

please suggest how to get size in GB.MB useing DOS

get a calculator divide by 1024

You can get the list of the directories and their size using the following command:

The following command should do and output the file as csv

Dir/s |Find /V “/”> Folder_info.csv

To get the file use

then save as and save where you want.

The ‘for’ command can return the size of a file using %

zI.
Type ‘for /?’ at a command prompt for the details.

CMD window size

Every time I open cmd the window size is 20×5. The problem is that even though the default settings are set to 80×25, it doesn’t do anything and the properties need to be changed every time the cmd is opened.

The problem started after my PC has been infected and now every time I open windows, there is a command prompt after logging in and since then all other cmd windows open is the 20×5 size. I’ve checked the registry and the values are correct, although they don’t take effect.

2 Answers 2

The registry entry HKCU\Console mentioned by NeveraX isn’t the whole story, every .lnk file used to start cmd.exe can have different settings not so easy discovered.

For HKCU\Console I once upon a time wrote a batch to enumerate the window/buffer sizes used:

Sample shorted output:

EDIT I’d also check the Autorun egistry key

I know that it’s a necrothread but this solution can help someone in the future. GNU Octave refused to work properly without this fix. So I spent several hours searching the internet and almost end up restoring Windows to default settings.

I fixed this issue by applying a registry file that contained default values for the registry keys «HKEY_CURRENT_USER\Console» and «HKEY_CURRENT_USER\Software\Microsoft\Command Processor».

If it doesn’t help there are some other solutions on this site for Windows 7, 8, 8.1, 10.

Читайте также:  Графический драйвер прекратил работу windows 10

How can I change the width of a Windows console window?

Is it possible to programmatically, or otherwise, increase the width of the Windows console window? Or do I need to create a wrapper program that looks and acts like the console somehow? Are there any programs around that do this already? I use Cygwin extensively in my development, and it seems a little ridiculous to me that all console windows in Windows are width limited.

If it matters at all, I’m running Windows XP.

11 Answers 11

You can increase it manually by right-clicking the tray icon and entering the options dialog.

There are also third-party terminal emulators for Windows, such as Console:

Simply run «mode cols,lines» to change the size of the current console window:

will resize the console window to 120 columns and 60 lines

This is a bad solution because it disables vertical scrolling.

There is a window’s api function to set the width. Here’s a tut on it. http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles6.html

If you right click on the title bar of a command window and choose properties, you can change widths in the Layout tab

If you’re programming C# here’s a method that worked for me (from the bottom of this page)

Quoted from the post: «My maximum console size that I could use was 127 columns and 57 rows because that’s all that my screen resolution will allow. Reset your screen resolution and this will change.

This is just one of those things that you are going to have to play around with in order for you to get it to display as you like. «

solutions did not work for me and I could not set the layout without getting a access error.

Fix was to close Cygwin, right click properties on the icon in the start menu and edit layout -> window -> height and then say yes to allowing administrator privileges to save settings. (not run as administrator).

now when running Cygwin always gives me a large window.

Windows 7 64bit.

To get all future console windows in a specific size you can create a shortcut to cmd.exe and then set size on the layout-tab of the shortcut properties.

In console properties at the Layout tab you can configure the following:

Screen Buffer Size Width

Window Size Width

The Window Size Width is how many characters per line will be visible. The Screen Buffer Size is the size of the line. If you set for example the Window Size Width at 100 and the Screen Buffer Size Width at 200, you will need to use the scrollbar to view the whole contents of lines with sizes between 100 and 200. Lines longer than 200 characters will appear in more than one line. This is useful if you have long lines and you want to copy them in a text file.

The same things apply for Windows PowerShell

Hey have you guys here ever thought of the possibility of launching and running Cygwin from within the windows command prompt/console? This is what I always do. Then you can do anything you want to the look of the console to make it sexy.

trying to get su from within cygwin can be difficult at times, especially when you are attempting to do some heavy crunching with the tools provided. People have tried all sorts of things from sudo SU for windows to what ever. when it can be as simple as passing on the administrator credentials from you the «user» (if you are the admin?) even without weird UAC pop ups. You can do this via a simple batch script. Have a below this of a screen grab of what my Cygwin looks like and this is running from a portable version of Cygwin too! No registry entries and any of that rubbish!
The batch file passes the credentials to bash and then bash changes directory (notice the double quotes are needed to pass this variable to the Cygwin colsole in order for it to work)

Note: the brackets like so < >in the above example are NOT included in the batch script. also note that windows CMD window is passing off the string to cygwin to interpret as multiple conditions; cygwin doesn’t read the quotes them selves but whats between them. the && is saying change directories and when you do execute the script ./execution-file-here when you get there.

It’s a double whammy you can launch a Cygwin or linux like application from within a MS-Windows window and not even type a letter of code or open a console or anything.

Читайте также:  Windows backup file versions

I keep this batch file inside of the /Cygwin/bin directory and create a Windows shortcut link on the desktop. Within the shortcut I can stylise the cmd shell window. Even go as far as transparency 😉

How to change Screen buffer size in Windows Command Prompt from batch script

I know you can do right click properties ->layout and there change it manually.

But how would you go about changing it from a Windows batch script?

I know you can change size of it from script using something like this

MODE CON: COLS=90 LINES=10

But how can you change buffer size?

The script will run for a while and sometimes before failing and exiting it takes some time, so I need larger buffer.

14 Answers 14

I was just searching for an answer to this exact question, come to find out the command itself adjusts the buffer!

The lines=70 part actually adjusts the Height in the ‘Screen Buffer Size’ setting, NOT the Height in the ‘Window Size’ setting.

Easily proven by running the command with a setting for ‘lines=2500’ (or whatever buffer you want) and then check the ‘Properties’ of the window, you’ll see that indeed the buffer is now set to 2500.

My batch script ends up looking like this:

I was just giving a try for max lines on windows 7 i can set using mode con command and found it to be 32766 2^15-2 and you can set it with following command

although you can set screen buffer size from the GUI too, but the max you can get is 9999.

sets the buffer, but also increases the window height to full screen, which is ugly.

You can change the settings directly in the registry :

The next cmd.exe you start has the increase buffer.

So this doesn’t work for the cmd.exe you are already in, but just use this in a pre-batch.cmd which than calls your main script.

Below is a very simple VB.NET program that will do what you want.

It will set the buffer to 100 chars wide by 1000 chars high. It then sets the width of the window to match the buffer size.

UPDATE

I modified the code to first set Console.WindowWidth and then set Console.BufferWidth because if you try to set Console.BufferWidth to a value less than the current Console.WindowWidth the program will throw an exception.

This is only a sample. you should add code to handle command line parameters and error handling.

There’s a solution at CMD: Set buffer height independently of window height effectively employing a powershell command executed from the batch script. This solution let me resize the scrollback buffer in the existing batch script window independently of the window size, exactly what the OP was asking for.

Caveat: It seems to make the script forget variables (or at least it did with my script), so I recommend calling the command only at the beginning and / or end of your script, or otherwise where you don’t depend on a session local variable.

Here’s what I did in case someone finds it useful (I used a lot of things according to the rest of the answers in this thread):

First I adjusted the layout settings as needed. This changes the window size immediately so it was easier to set the exact size that I wanted. By the way I didn’t know that I can also have visible width smaller than width buffer. This was nice since I usually hate a long line to be wrapped.

Then after clicking ok, I opened regedit.exe and went to «HKEY_CURRENT_USER\Console». There is a new child entry there «%SystemRoot%_system32_cmd.exe». I right clicked on that and selected Export:

I saved this as «cmd_settings.reg». Then I created a batch script that imports those settings, invokes my original batch script (name batch_script.bat) and then deletes what I imported in order for the command line window to return to default settings:

This is a sample batch that could be invoked («batch_script.bat»):

Don’t forget the exit command at the end of your script if you want the reg delete line to run after the script execution.

Get Folder Size from Windows Command Line

Is it possible in Windows to get a folder’s size from the command line without using any 3rd party tool?

I want the same result as you would get when right clicking the folder in the windows explorer → properties.

18 Answers 18

You can just add up sizes recursively (the following is a batch file):

However, this has several problems because cmd is limited to 32-bit signed integer arithmetic. So it will get sizes above 2 GiB wrong 1 . Furthermore it will likely count symlinks and junctions multiple times so it’s at best an upper bound, not the true size (you’ll have that problem with any tool, though).

Читайте также:  Как создать загрузочную флешку windows 10 с помощью виндовс

An alternative is PowerShell:

If you want it prettier:

You can use this directly from cmd :

1 I do have a partially-finished bignum library in batch files somewhere which at least gets arbitrary-precision integer addition right. I should really release it, I guess 🙂

There is a built-in Windows tool for that:

This will print a lot of unnecessary information but the end will be the folder size like this:

If you need to include hidden folders add /a .

I suggest to download utility DU from the Sysinternals Suite provided by Microsoft at this link http://technet.microsoft.com/en-us/sysinternals/bb896651

While you are at it, take a look at the other utilities. They are a life-saver for every Windows Professional

Same but Powershell only:

This should produce the following result:

If you have git installed in your computer (getting more and more common) just open MINGW32 and type: du folder

Here comes a powershell code I write to list size and file count for all folders under current directory. Feel free to re-use or modify per your need.

I recommend using https://github.com/aleksaan/diskusage utility which I wrote. Very simple and helpful. And very fast.

Just type in a command shell

and get list of folders arranged by size

This example was executed at 272ms on HDD.

You can increase depth of subfolders to analyze, for example:

and get sizes not only for selected folders but also for its subfolders

*** 3.5Tb on the server has been scanned for 3m12s**

This code is tested. You can check it again.

I guess this would only work if the directory is fairly static and its contents don’t change between the execution of the two dir commands. Maybe a way to combine this into one command to avoid that, but this worked for my purpose (I didn’t want the full listing; just the summary).

I got du.exe with my git distribution. Another place might be aforementioned Microsoft or Unxutils.

Once you got du.exe in your path. Here’s your fileSizes.bat 🙂

I think your only option will be diruse (a highly supported 3rd party solution):

The Windows CLI is unfortuntely quite restrictive, you could alternatively install Cygwin which is a dream to use compared to cmd. That would give you access to the ported Unix tool du which is the basis of diruse on windows.

Sorry I wasn’t able to answer your questions directly with a command you can run on the native cli.

::Get a number of lines that Dir commands returns (/-c to eliminate number separators: . ,) [«Tokens = 3» to look only at the third column of each line in Dir]

FOR /F «tokens=3» %%a IN (‘dir /-c «%folderpath%»‘) DO set /a i=!i!+1

Number of the penultimate line, where is the number of bytes of the sum of files:

Finally get the number of bytes in the penultimate line — 3rd column:

As it does not use word search it would not have language problems.

Limitations:

  • Works only with folders of less than 2 GB (cmd does not handle numbers of more than 32 bits)
  • Does not read the number of bytes of the internal folders.

Change C:\Program Files to whatever folder you want and change %A to %%A if using in a batch file

It returns the size of the whole folder, including subfolders and hidden and system files, and works with folders over 2GB

It does write to the screen, so you’ll have to use an interim file if you don’t want that.

The following script can be used to fetch and accumulate the size of each file under a given folder.
The folder path %folder% can be given as an argument to this script ( %1 ).
Ultimately, the results is held in the parameter %filesize%

Note: The method calcAccSize can also print the content of the folder (commented in the example above)

So here is a solution for both your requests in the manner you originally asked for. It will give human readability filesize without the filesize limits everyone is experiencing. Compatible with Win Vista or newer. XP only available if Robocopy is installed. Just drop a folder on this batch file or use the better method mentioned below.

To be able to use this batch file conveniently put it in your SendTo folder. This will allow you to right click a folder or selection of folders, click on the SendTo option, and then select this batch file.

To find the SendTo folder on your computer simplest way is to open up cmd then copy in this line as is.

Оцените статью