Calculate the size of the contents of a folder. Used to determine whether sketches are empty or not. Note that the function calls itself recursively.
(File folder)
| 358 | * Note that the function calls itself recursively. |
| 359 | */ |
| 360 | static public long calcFolderSize(File folder) { |
| 361 | int size = 0; |
| 362 | |
| 363 | String files[] = folder.list(); |
| 364 | // null if folder doesn't exist, happens when deleting sketch |
| 365 | if (files == null) return -1; |
| 366 | |
| 367 | for (int i = 0; i < files.length; i++) { |
| 368 | if (files[i].equals(".") || |
| 369 | files[i].equals("..") || |
| 370 | files[i].equals(".DS_Store")) continue; |
| 371 | File fella = new File(folder, files[i]); |
| 372 | if (fella.isDirectory()) { |
| 373 | size += calcFolderSize(fella); |
| 374 | } else { |
| 375 | size += (int) fella.length(); |
| 376 | } |
| 377 | } |
| 378 | return size; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /** |