필터 지우기
필터 지우기

How to segregate folders level wise and list the files folderwise

조회 수: 7 (최근 30일)
Mukund
Mukund 2019년 10월 5일
답변: Image Analyst 2019년 10월 5일
In Matlab 2016 onwards, commands like dir(**/*.extension) is available. However, it lists all the file list with its Path. The task afterward is critical. 1. Obtain Subfolders 2. Obtain Files and Subsubfolders with their level. 3. Extract the directory name and file name in cell array.
Are there modified ways or shortcut commands to obtain this info.

채택된 답변

Image Analyst
Image Analyst 2019년 10월 5일
There is a .isdir property on the returned files that you can check. In addition there is a function called isfolder() that you can also use. Try this:
files = dir('**/*.*')
areFolders = [files.isdir]
folders = files(areFolders)
dotOrDotDot = strcmp('.', {folders.name}) | strcmp('..', {folders.name})
folders = folders(~dotOrDotDot)
folderNames = {folders.name}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by