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 个评论
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
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
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'));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Name Construction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!