Borrar filtros
Borrar filtros

List only top directories

8 visualizaciones (últimos 30 días)
balandong
balandong el 17 de Abr. de 2017
Respondida: Image Analyst el 17 de Abr. de 2017
Dear Matlab_User
May I know the best approach to list down only the first level directories.
For example, I have a dir with subfolder inside, such as
C:\Users\1st_level_a\2nd_level
C:\Users\1st_level_b\2nd_level
C:\Users\1st_level_c\2nd_level\3rd_level.
However, I am only interested to obtain the url name for the 1st_level,
C:\Users\1st_level_a
C:\Users\1st_level_b
C:\Users\1st_level_c
I tried using the genpath (), however, genpath return me the sub dir as well.
Any suggestion is most welcome,
Cheers,
Rodney

Respuesta aceptada

balandong
balandong el 17 de Abr. de 2017
I found a dirty workaround, but I welcome if there are any more efficient script to replace my method, thansk
start_path = fullfile(matlabroot, 'C:\Users\');
% Ask user to confirm or change.
topLevelFolder = uigetdir(start_path);
list=dir(topLevelFolder); %get info of files/folders in current directory
dirnames={list([list.isdir]).name};
dirnames=dirnames(~(strcmp('.',dirnames)|strcmp('..',dirnames)));
for i = 1:length (dirnames)
s (i) = strcat (topLevelFolder,'\', dirnames (i))
end

Más respuestas (1)

Image Analyst
Image Analyst el 17 de Abr. de 2017
Try this:
startingFolder = 'C:/windows/media';
files = dir(startingFolder)
folderIndexes = [files.isdir]
folders = {files(folderIndexes).name} % Note, first two are . and ..
folders = folders(3:end) % Ignore . and .., if you want.

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by