Counts the size of a directory recursively (sum of the length of all files).

@param directory directory to inspect, must not be null
@return size of directory in bytes, 0 if directory is security restricted
965057
public static long getDirectorySize(File directory) {
        if (!directory.exists()) {
            throw new IllegalArgumentException(directory + " does not exist");
        }

        if (!directory.isDirectory()) {
            throw new IllegalArgumentException(directory + " is not a directory");
        }
        long size = 0;
        File[] files = directory.listFiles();
        if (files == null) {
            // null if security restricted
            return 0L;
        }
        for (int i = 0; i < files.length; i++) {
            File file = files[i];

            if (file.isDirectory()) {
                size += getDirectorySize(file);
            } else {
                size += file.length();
            }
        }
        return size;
    }
152255
public void addDirectory(File dir) {
    File[] ndirs = new File[directories.length + 1];
    System.arraycopy(directories, 0, ndirs, 0, directories.length);
    ndirs[ndirs.length - 1] = dir;
    directories = ndirs;
  }
229254
public static boolean deleteDirectory(File dir)
    {

        if (dir.canWrite()) {
            File [] subFiles = dir.listFiles();

            for(int i=0; i<subFiles.length; i++) {
                if (subFiles[i].isDirectory())
                    deleteDirectory(subFiles[i]);
                else
                    subFiles[i].delete();
            }

        }

        return dir.delete();

    }
972787
static function getDirSize($dir)
    {
        $size = 0;
        $dirs = array_diff(scandir($dir), array('.', '..'));
        foreach ($dirs as $d){
            $d = $dir.'/'.$d;
            $size+= filesize($d);
            if (is_dir($d)){
                $size+= self::getDirSize($d);
            }
        }
        return $size;
    }
977797
public static void recursiveDelete(Path directory) throws IOException   {

        try {
            Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws java.io.IOException {
                    try {
                        Files.delete(file);
                    } catch (NoSuchFileException ignore) {}
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, java.io.IOException exc) throws java.io.IOException {
                    try{
                        Files.delete(dir);
                    }catch (NoSuchFileException ignore){}
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (NoSuchFileException ignore) {}

    }
727360
public static List<File> getAllFilesFromDir(final File dir)
	{
		final List<File> foundedFileList = new ArrayList<>();
		final File[] children = dir.getAbsoluteFile().listFiles();
		if (children == null || children.length < 1)
		{
			return foundedFileList;
		}
		for (final File child : children)
		{
			// if the entry is not a directory
			if (!child.isDirectory())
			{
				// then
				// entry is a file
				foundedFileList.add(child.getAbsoluteFile());
			}
		}
		return foundedFileList;
	}
1129681
public long readExecutionCount (Path dir) throws IOException {
    State state = loadState(fs, dir);
    return Long.parseLong(state.getProp(CompactionSlaEventHelper.EXEC_COUNT_TOTAL, "0"));
  }
316875
def size(self):
        """"""
        total_size = 0
        for dir_path, dir_names, filenames in os.walk(self.dir):
            for f in filenames:
                fp = os.path.join(dir_path, f)
                total_size += os.path.getsize(fp)
        return total_size
681882
private FileHandlerResult processDir(final File dir) {
        // CHECKSTYLE:ON

        final FileHandlerResult dirResult = handler.handleFile(dir);
        if (dirResult == FileHandlerResult.STOP) {
            return FileHandlerResult.STOP;
        }
        if (dirResult == FileHandlerResult.SKIP_ALL) {
            return FileHandlerResult.CONTINUE;
        }

        final File[] files = dir.listFiles();
        if (files != null) {
            final List<File> sortedFiles = asList(files);
            for (int i = 0; i < sortedFiles.size(); i++) {
                final File file = sortedFiles.get(i);
                FileHandlerResult result = FileHandlerResult.CONTINUE;
                if (file.isDirectory() && (dirResult != FileHandlerResult.SKIP_SUBDIRS)) {
                    result = processDir(file);
                } else if (file.isFile() && (dirResult != FileHandlerResult.SKIP_FILES)) {
                    result = handler.handleFile(file);
                }
                if (result == FileHandlerResult.STOP) {
                    return FileHandlerResult.STOP;
                }
                if (result == FileHandlerResult.SKIP_ALL) {
                    return FileHandlerResult.CONTINUE;
                }
            }
        }

        return FileHandlerResult.CONTINUE;

    }
361520
public static File mkdir(File dir) {
		if (dir == null) {
			return null;
		}
		if (false == dir.exists()) {
			dir.mkdirs();
		}
		return dir;
	}
497376
public static void checkDirectory(File directory) {
        if (!(directory.exists() || directory.mkdirs())) {
            throw new ReportGenerationException(
                    String.format("Can't create data directory <%s>", directory.getAbsolutePath())
            );
        }
    }
470421
@Nonnegative
    public static int count(@Nonnull final Path dir) throws IOException {
        try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
            return Iterables.size(stream);
        } catch (DirectoryIteratorException ex) {
            // I/O error encounted during the iteration, the cause is an IOException
            throw ex.getCause();
        }
    }
95183
public static function dirSize($directory)
    {
        $size = 0;
        foreach (new \RecursiveIteratorIterator(
                     new RecursiveDirectoryIterator($directory, \FilesystemIterator::KEY_AS_PATHNAME)
                 ) as $file) {
            $size += $file->getSize();
        }

        return $size;
    }
540180
public static function getDirectorySize($dir) {
		if (is_dir($dir)) {
			$totalSize = 0;
			$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
			foreach($iterator as $file) {
				$totalSize += $file->getSize();
			}
			return $totalSize;
		}
		return false;
	}
462612
public int getScriptCount(File dir) {
		int scripts = 0;
		
		for (ScriptType type : this.getScriptTypes()) {
			File locDir = new File(dir, type.getName());
			if (locDir.exists()) {
				for (File f : locDir.listFiles()) {
					String ext = f.getName().substring(f.getName().lastIndexOf(".") + 1);
					String engineName = this.getEngineNameForExtension(ext);
					if (engineName != null) {
						scripts++;
					}
				}
			}
		}
		return scripts;
	}
906642
static long calculateDirSizeAndSave(final File dir) throws IOException {
    final Path path = Paths.get(dir.getPath(), FlowPreparer.PROJECT_DIR_SIZE_FILE_NAME);
    if (!Files.exists(path)) {
      final long sizeInByte = FileUtils.sizeOfDirectory(dir);
      FileIOUtils.dumpNumberToFile(path, sizeInByte);
      return sizeInByte;
    } else {
      return FileIOUtils.readNumberFromFile(path);
    }
  }
210418
def _calc_dir_size(path):
    
    dir_size = 0
    for (root, dirs, files) in os.walk(path):
        for fn in files:
            full_fn = os.path.join(root, fn)
            dir_size += os.path.getsize(full_fn)

    return dir_size