Count how many files in directory PHP
You can simply do the following : $fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS); printf(“There were %d Files”, iterator_count($fi));
You can simply do the following : $fi = new FilesystemIterator(__DIR__, FilesystemIterator::SKIP_DOTS); printf(“There were %d Files”, iterator_count($fi));
Count() is an extension method introduced by LINQ while the Count property is part of the List itself (derived from ICollection). Internally though, LINQ checks if your IEnumerable implements ICollection and if it does it uses the Count property. So at the end of the day, there’s no difference which one you use for a … Read more
How about this: fgrep -o f <file> | wc -l Note: Besides much easier to remember/duplicate and customize, this is about three times (sorry, edit! botched the first test) faster than Vereb’s answer.
The documentation on counting says that for group_by queries it is better to use func.count(): from sqlalchemy import func session.query(Table.column, func.count(Table.column)).group_by(Table.column).all()
Yes. With a simple window function: SELECT *, count(*) OVER() AS full_count FROM tbl WHERE /* whatever */ ORDER BY col1 OFFSET ? LIMIT ? Be aware that the cost will be substantially higher than without the total number, but typically still cheaper than two separate queries. Postgres has to actually count all rows either … Read more
The problem is that count is intended to count the indexes in an array, not the properties on an object, (unless it’s a custom object that implements the Countable interface). Try casting the object, like below, as an array and seeing if that helps. $total = count((array)$obj); Simply casting an object as an array won’t … Read more
This snippet works in the specific situation where you have a boolean: it answers “how many non-Ns are there?”. SELECT LEN(REPLACE(col, ‘N’, ”)) If, in a different situation, you were actually trying to count the occurrences of a certain character (for example ‘Y’) in any given string, use this: SELECT LEN(col) – LEN(REPLACE(col, ‘Y’, ”))
COUNT(*) counts all rows COUNT(column) counts non-NULLs only COUNT(1) is the same as COUNT(*) because 1 is a non-null expressions Your use of COUNT(*) or COUNT(column) should be based on the desired output only.
You need to count the number of rows: row_count = sum(1 for row in fileObject) # fileObject is your csv.reader Using sum() with a generator expression makes for an efficient counter, avoiding storing the whole file in memory. If you already read 2 rows to start with, then you need to add those 2 rows … Read more