How to count how many sub folders under a folder
66 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
In a folder, there are many sub folder, how do we count how many sub folder they are?
1 Commento
Stephen23
il 4 Mar 2016
Modificato: Stephen23
il 3 Set 2022
Note that KSSV's answer actually counts the total contents of a folder, including any files.
See also:
As Walter Roberson wrote in that last link: "In short: if your code assumes that '.' and '..' are the first two entries in a directory, your code has a bug (even in MS Windows). If your code assumes that directory entries are returned in any sorted order, your code has a bug (in all OS.)"
Risposte (2)
KSSV
il 4 Mar 2016
go the folder...and use
k = dir ;
N = length(k)-2 ;
N should be the number of sub folders.
7 Commenti
Stephen23
il 14 Mar 2022
The correct answer would be something like this:
P = 'absolute or relative path to the folder';
S = dir(P);
N = nnz(~ismember({S.name},{'.','..'})&[S.isdir])
0 Commenti
Vedere anche
Categorie
Scopri di più su File Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!