How do I display list of folder (as text file)

4 ビュー (過去 30 日間)
Minh Nguyen
Minh Nguyen 2018 年 5 月 7 日
コメント済み: Minh Nguyen 2018 年 5 月 7 日
Hello, I'm trying to make a program so that it can make a list of file(s) in a folder and display them in the Command Window so the user can see it.
I have tried to use dir function to get the list of files but I don't know how to make it into something that can be displayed. I don't know how to go from here so this is the only thing I have so far:
a = dir;
a.name %I got all the files name on this step
I'm trying to achieve something like this in the command window:
>>Existing files: %I'm trying to display this list, which varies depends on the files in the folder
- a.m
- b.txt
Choose file to load:
>> <User input>
Thank you

採用された回答

David Fletcher
David Fletcher 2018 年 5 月 7 日
files=dir
sprintf('%s \n',files.name)
fName=input('choose file:','s')
  4 件のコメント
David Fletcher
David Fletcher 2018 年 5 月 7 日
After a bit of searching and testing you can use
files=files(~ismember({files.name},{'.','..'}))
to remove the offending entries
Minh Nguyen
Minh Nguyen 2018 年 5 月 7 日
Thanks for the help!

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

その他の回答 (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