Simple and elegant! I like this one best, but isn't the set-location unnecessary? FullName , that way you come out the other side without the current directory changing underneath you.
Thanks BenderBoy. FullName directly. Just type in a command shell diskusage. You can increase depth of subfolders to analyze, for example: diskusage. Ro Yo Mi 14k 4 4 gold badges 32 32 silver badges 40 40 bronze badges.
Alexander Anufriev Alexander Anufriev 1 1 silver badge 4 4 bronze badges. New version released! Version 2. Please, make note that you are an author. From stackoverflow. Yes, I am author of github. This code is tested. You can check it again. Chienvela Chienvela 21 1 1 bronze badge.
Thanks, it works for me with folders which smaller than 1GB, but for example, I have a folder of 3,,, bytes 3. Steve Steve 21 3 3 bronze badges. Once you got du. Here's your fileSizes. Frank Nocke Frank Nocke 8, 4 4 gold badges 62 62 silver badges 97 97 bronze badges.
Illizian Illizian 5 5 silver badges 12 12 bronze badges. If you just need du then Cygwin is way overkill. Just go with GnuWin Indeed it is overkill, but it's also awesome. In my humble opinion Cygwin may be useful to some but it's far from awesome and rather horrible. But I guess Unix users say the same about Wine. It takes some setting up, but Cygwin is brilliant for those among us who miss the nix shell in Windows, personally I don't like Powershell I may have to check GnuWin out though.
Thanks Joey. 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.
Gustavo Davico Gustavo Davico 11 1 1 bronze badge. Lior Kirshner Lior Kirshner 4 4 silver badges 9 9 bronze badges. For anyone worried Robocopy will move files.. In addition, Robocopy is not 3rd party, Robocopy is installed in Windows by default from Vista up, XP you need to install it.
Thanks for the addition. The findstr is used to discard all the dir lines that does not include size information. But all the intermediate sizes one for each folder are not necessary. It is necessary to reduce the volume of data to process from command output. In the indicated scenario, the only way to remove the findstr is to use a temporary file.
For cases like this the pipe is a faster solution. This feature makes me very happy :- Thanks for demonstrating. FileSystemObject" ; WScript.
Echo fso. GetFolder '. GetFolder WScript. Unnamed 0. Size ; The only limitation is you must have access to all folders and files? You could use Scripting. FileSystemObject even in a powershell script where both powerscript and cscript are present on Windows PC out of the box. See blogs. OpenTextFile "size. I don't want to muck around changing a lot of folders en masse — StanM. I think that looping over each line of output of the compact or dir command is inefficient and can be avoided by filtering the interim result: echo off REM dirsize.
Icemanind Icemanind Here it is:. Drop this script into a directory in your path, and you can quickly find the sizes for directories in your file system. Remember that it outputs objects, so you can add tasks such as sort and filter, for example:.
The entire script can be downloaded from the Script Repository. Thank you, Bill, for writing an interesting and useful blog. Join me tomorrow for more Windows PowerShell cool stuff. I invite you to follow me on Twitter and Facebook.
If you have any questions, send email to me at scripter microsoft. See you tomorrow. Until then, peace. Comments are closed. Scripting Forums. PowerShell Forums. PowerShell on TechCommunity. May 25th, Select-Object CmdLet is used to present the result and convert bytes into megabytes for the folder size. REMEMBER: I have used a stand-alone enabled remoting environment remoting on the single computer and if I do not provide the correct credentials remoting will return the error like on the screenshot below.
Configuring PowerShell Remoting can be sometimes very tricky so be patient. Here is the result of the folder size in kilobytes. Notice that the result has many decimal places so in the next example, we will format the result to get with just two decimal places. Let me just quickly go through each of CmdLets and parameters used with it and why we have used them. Select-Object CmdLet is used to present the result and convert bytes into kilobytes for the folder size.
In this example, we will just format our result to return with two decimal places only. Here is the result of the folder size in megabytes. Here is the result of the folder size in gigabytes. If for whatever reason we want to have folder size in kilobytes , megabytes , and gigabytes well-formatted using PowerShell here is the example code:.
Thanks to the readers question I am adding this section to the article. You already know that the same result can be seen using Windows Explorer Properties like in the screenshot below. Get-ChildItem CmdLet is used to list all the files within folders and subfolders. Here is the explanation of each parameter used:.
Result is pipelined to Measure-Object CmdLet. Its only purpose is to count the files for us. Finally we make the property name of the result to be readable using Select-Object CmdLet and expression feature.
Get-ChildItem CmdLet is used to list all the subfolders and here is the explanation of each parameter used:. Its only purpose is to count the folders for us. If you want ot have the result of both number of files and subfolders within specified folder using PowerShell as one result.
Here is the solution provided:. In this example, we use the lines of code from previous two examples. Here we just use Add-Member CmdLet to have the results in one row. This will provide the result for us that shows both number of folders and files within specified folder using PowerShell. Directory parameter tells PowerShell to look only for folders and no files.
0コメント