How to list files with multiple extensions?
34 次查看(过去 30 天)
显示 更早的评论
Suppose I want mp3 or avi files from a folder, on Unix I could do
ls *.{mp3|avi}
Is there a clean one-liner way to do this in matlab? Presently, I can do it in two lines by doing the following:
f = dir(folder)
f(~cellfun(@isempty,regexpi({f.name},'.*(mp3|avi)'))).name
However, I find this rather ugly compared to the simplicity of the first expression.
Thanks, Kevin
1 个评论
回答(3 个)
Doug Hull
2012-10-24
Can you run the command twice with two filters? The results would be two structures of the same format that could then be appended together.
2 个评论
Sean de Wolski
2012-10-24
@Kevin, a for-loop over a cell array containing the extentions would allow it to scale, though concatenating structures is ugly.
Sean de Wolski
2012-10-24
You could just farm that command out to Unix if you are on a unix system...
ANKUR WADHWA
2019-11-6
编辑:Cris LaPierre
2024-1-9
Though the thread is very old still for users who are looking for an easy way a very simple existing solution on Matlbcentral
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!