I need to calculate the physical size of a directory. A naive algorithm for this could be:
public static long getFolderSize(File dir) { long size = 0; for (File file : dir.listFiles()) { if (file.isFile()) { System.out.println(file.getName() + " " + file.length()); size += file.length(); } else size += getFolderSize(file); } return size; }
but how to deal with symbolic links?
source share