Noél Dubau Posted April 7, 2010 Posted April 7, 2010 (edited) In the ScriptMaster Sample file there is a script giving the size of a file. Has someome done, and is it possible to get the size of a folder with all its sub-folders and files ? Thanks Noël Edited April 7, 2010 by Guest
Jesse Barnum Posted April 7, 2010 Posted April 7, 2010 File startingFolder = new File( path ); if( ! startingFolder.exists() ) throw new IllegalArgumentException("No such folder: " + startingFolder.getAbsolutePath() ); return getSizeRecursive( startingFolder ); long getSizeRecursive( File fileOrFolder ) { if( fileOrFolder.isDirectory() ) { long subfolderSize = 0; for( File eachFile : fileOrFolder.listFiles() ) { subfolderSize += getSizeRecursive( eachFile ); } return subfolderSize; } else { return fileOrFolder.length(); } }
Noél Dubau Posted April 7, 2010 Author Posted April 7, 2010 The french novice says an immense "Thanks" to the apprentice ! Regards Noël
Recommended Posts
This topic is 5355 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now