A question about list folder contents with dir

Hi,
I used uigetdir and dir to list all subfolders with the following code:
path_dir=uigetdir('C:\Documents','Select a folder');
list_folder=dir(path_dir);
allFolder_list={list_folder.name};
But the names in the list have two dot files, which don't exist actually in the folder. What are they and how to remove them?

댓글 수: 1

xiaobo wu
xiaobo wu 2024년 1월 31일
이동: Voss 2024년 1월 31일
Thank you all for the answers! They are helpful!

댓글을 달려면 로그인하십시오.

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 1월 26일
편집: Dyuman Joshi 2024년 1월 26일

0 개 추천

This notation is used in filesystems (and anywhere they are implemented/used) -
. refers to the current directory/folder.
.. refers to the parent directory/folder. This can also be used to access the parent directory/folder.
For example, if your directory is C:\Users\Bob, . refers to C:\Users\Bob and .. refers to C:\Users.
To remove them -
d=dir;
d=d(~ismember({d.name},{'.','..'}));

댓글 수: 2

Years ago I made the suggestion to them to have additional inputs to dir to list files only and folders only. You can too -- just give it a star rating at the bottom of the help entry for dir. I just did it again. I can't believe it's taking them so long to implement this simple option but it depends on how many people are asking for it.
Note that
d = dir;
d = d(~[d.isfolder]);
would remove . and .. and all folders, leaving only regular files.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

질문:

2024년 1월 26일

이동:

2024년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by