Hi I'm trying to figure out the best way to get a directory/folder size. I using for loop to list all the directories. while running the for loop, i want to check the size of each directory. Do i need to be creating a new job for each directory in the for loop and then try pulling the job. Ive tried doing this but as i have read from earlier post, that it creating a temporary path, and its not actually setting the new job as the directory that i am creating. Does any body have any suggestions?
Thank you
Directory Size
Re: Directory Size
Could you post the script you're working on? This should be pretty simple with Process.execute. If you're on a unix based OS, you should be able to use something like 'du' to get a directory size in your loop.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Re: Directory Size
Here's a recursive function to calculate the size of a directory and subdirectories.
Learn Javascript scripting & more at the Advanced Enfocus Switch concepts seminar during Graph Expo 2015 trade-show
Contact dkelly@apago.com for more information
Code: Select all
function calculateDirectorySize( dirName : String )
{
var dirSize = 0;
var theDir = new Dir(dirName);
var entries = theDir.entryList("*", Dir.All|Dir.NoDotAndDotDot, Dir.DirsFirst);
for (var i=0; i<entries.length; i++) {
var fn = dirName+"/"+entries[i];
if (File.isDir(fn)) {
dirSize += calculateDirectorySize(fn);
} else {
var f = new File(fn);
dirSize += f.size;
delete f;
}
}
delete theDir;
return dirSize;
}
var dirName = "/Users/dkelly/Downloads";
var dirSize = calculateDirectorySize(dirName)
s.log(1, "files in " + dirName + " are " + Math.floor(dirSize/1048576) + " MB");
Learn Javascript scripting & more at the Advanced Enfocus Switch concepts seminar during Graph Expo 2015 trade-show
Contact dkelly@apago.com for more information