フィルターのクリア

A question about list folder contents with dir

4 ビュー (過去 30 日間)
xiaobo wu
xiaobo wu 2024 年 1 月 26 日
移動済み: Voss 2024 年 1 月 31 日
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 日
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 件のコメント
Image Analyst
Image Analyst 2024 年 1 月 26 日
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.
Walter Roberson
Walter Roberson 2024 年 1 月 26 日
Note that
d = dir;
d = d(~[d.isfolder]);
would remove . and .. and all folders, leaving only regular files.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by