can not find a file list with fonction ( dir)

16 次查看(过去 30 天)
hello
I used a function (dir) to get a list of wav files, but it returns an empty list
Folder = 'the folder which contain files';
List= dir([folder '*.wav']);
Why the list is empty?
thank you
  3 个评论
ChihabEddine CHIHEB
thank you , it was it
list = dir([folder ,'/*.wav']);
Stephen23
Stephen23 2023-3-28
Best avoided. Using FULLFILE is more robust (e.g. it will take into acount if the path already has a trailing path separator character, which your code does not do). The best approach by far is to use FULLFILE. You should use FULLFILE.

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2023-3-27
Variables in MATLAB are case sensitive. So Folder is not the same as folder. You define Folder, but then use folder in your dir command.
If that is just a typo here, then the next most likely reason is that you have forgotten to include backslash (or forward slash, depending on your system) at the end of your folder path. A good way to avoid this is by using fullfile to build your path. Here's a simple example using a relative folder path.
Folder = '.\MATLAB Answers'
dir(fullfile(Folder, '*.wav'))
  8 个评论
Cris LaPierre
Cris LaPierre 2023-3-28
编辑:Cris LaPierre 2023-3-28
Use the Copy option from my post rather than typing the code yourself.
You are erroneously including square brackets "[]", which is preventing fullfile from doing its thing.
dir(fullfile(folder,'*.wav'));
Stephen23
Stephen23 2023-3-28
编辑:Stephen23 2023-3-29
@ChihabEddine CHIHEB: compare:
dir(fullfile(Folder, '*.wav')) % the correct code, as Chris LaPierre showed you.
dir(fullfile([folder ,'*.wav'])); % your code, with square brackets.
% ^ ^ why do you keep adding these?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Name Construction 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by