I was using count(glob("test/*"))
to count the sub-folders in the test
folder, but now that I also have files in the test
folder, not just folders, I get incorrect results. Is there a way to modify the glob
pattern so that it'll return only the folders, not files?
I've thought about a workaround. Get the total count of folders and files, get the count of files only, and then, subtract the count of files from the count of the whole.
$total_items = count(glob("test/*"));
$total_files = count(glob("test/*.*"));
$folder_count = $total_items - $total_files;
This works, but there might be a simpler way to do this.
Right-click on the folder and select the “Properties” option. The “Properties” window will open and you will be able to see the number of files and subdirectories located in the directory selected.
Using the ls Command. The ls command lists the directories and files contained in a directory. The ls command with the -lR options displays the list (in long format) of the sub-directories in the current directory recursively. Then, we use the grep command to search for a string or pattern in the input.
Choose File-> section Info-> button Cleanup Tools-> Mailbox Cleanup…Now click on [View Mailbox Size…] and you'll be presented with a list of your folders and subfolders. You'll need to count the folders yourself, as they are not counted by the system, but their size is listed.
You have to use the option GLOB_ONLYDIR
to return only directories:
$total_items = count( glob("test/*", GLOB_ONLYDIR) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With