code: public static long countAllFilesInDirectory(final File dir, long length,
  		final boolean includeDirectories)
  	{
  		// Get all files
  		final File[] children = dir.getAbsoluteFile().listFiles();
  		if (children == null || children.length < 1)
  		{
  			return length;
  		}
  		for (final File element : children)
  		{
  			// if the entry is a directory
  			if (element.isDirectory())
  			{ // then
  				// if directories shell be include
  				if (includeDirectories)
  				{ // then
  					// increment the length
  					length++;
  				}
  				// find recursively in the directory the files.
  				length = countAllFilesInDirectory(element, length, includeDirectories);
  			}
  			else
  			{
  				// increment length...
  				length++;
  			}
  		}
  		return length;
  	}
docs: Counts all the files in a directory recursively. This includes files in the subdirectories.
  
  @param dir
  the directory.
  @param length
  the current length. By start is this 0.
  @param includeDirectories
  If this is true then the directories are in the count too.
  @return the total number of files.