Script for Determining Size of Subfolders
So another JScript today that will spit out a comma separated text file listing all the subfolders for a given path and their size.
// folder_size.js - This script generates a csv file with the name
// and size of subfolders for a designated folder.
// Author - Jace Gregg
// Version 1.0 - 04 February 2009
// -----------------------------------------------------------------'
var cTITLE = "Folder Size";
var folderPath = "W:\\"; // This is the root folder - CHANGE THIS
try {
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var objShell = WScript.CreateObject("Wscript.Shell");
var outputPath = objShell.SpecialFolders.Item("Desktop") + "\\" + cTITLE + ".txt"; // THIS IS WHERE YOUR OUTPUT FILE GOES
var folder = fso.GetFolder(folderPath);
var subFolders = new Enumerator(folder.SubFolders)
var fso, f1, ts;
var ForWriting = 2;
fso.CreateTextFile(outputPath);
var file = fso.GetFile(outputPath);
var output = file.OpenAsTextStream(ForWriting, true);
output.WriteLine("Path,Size (bytes)");
for (;!subFolders.atEnd(); subFolders.moveNext())
{
output.WriteLine(subFolders.item() + "," + subFolders.item().size);
}
output.Close();
}
catch(e) {
msgbox("Error " + e.number + "\n\n" + e.description, null, null, 16);
}
function msgbox(message, title, popupTime, nType) {
if(title == null) {
title = "Dawson Scripting: " + cTITLE + " - Folder Size Report Generator";
}
if(popupTime == null) {
popupTime = 0;
}
var objWSH = WScript.CreateObject("Wscript.Shell");
return objWSH.Popup(message, popupTime, title, nType);
}
I’m having to move a Home Folders folder from one server to another and I’m wanting to move the smallest first. This let me get a csv that I could manipulate in Excel and now I’m off to start the migration.