i need a function that will take adirectory name and return a list of all mp3 files present in that directory and all it's sub directories?
Show older comments
i want to get the all (.mp3) file names along with full path in matlab. kindly help me.
Accepted Answer
More Answers (1)
Geoff Hayes
on 2 Jan 2015
Muhammad - look in the File Exchange for a recursive directory listing submission. One such example is Thomas Vanaret's rdir. Using this file, from the current directory, you could try something like
rdir([pwd '/*.mp3'])
or
rdir([pwd '\*.mp3'])
depending upon your OS.
4 Comments
Muhammad Naveed
on 2 Jan 2015
Geoff Hayes
on 2 Jan 2015
The above function will return a structure with the full path to each file. For example, if I run then following command to find text files in my current directory (note that I am using a Mac)
>> rdir([pwd '/*.txt'])
21 kb 28-Dec-2014 13:46:46 /Users/geoff/matlab/testing2/KEmode2_G201.txt
224 b 24-Nov-2014 12:30:41 /Users/geoff/matlab/testing2/RealInfo.txt
979 kb 20-Nov-2014 12:08:10 /Users/geoff/matlab/testing2/data.txt
3 kb 24-Nov-2014 09:35:34 /Users/geoff/matlab/testing2/myConv.cpp.txt
341 kb 20-Nov-2014 17:03:56 /Users/geoff/matlab/testing2/myOutput.txt
2 kb 07-Dec-2014 14:21:08 /Users/geoff/matlab/testing2/readString.F.txt
98 b 12-Dec-2014 12:18:03 /Users/geoff/matlab/testing2/test.txt
204 kb 28-Nov-2014 09:13:59 /Users/geoff/matlab/testing2/test2.txt
204 kb 28-Nov-2014 09:14:08 /Users/geoff/matlab/testing2/test3.txt
I see the above output. If I save this to a structure as
myTxtFiles = rdir([pwd '/*.txt']);
then
>> myTxtFiles(1).name
ans =
/Users/geoff/matlab/testing2/KEmode2_G201.txt
and so I can get the full name and path to the text file.
Muhammad Naveed
on 3 Jan 2015
Geoff Hayes
on 3 Jan 2015
The above example is for one directory. For sub-directories you can try
>> rdir([pwd '/**/*.txt'])
21 kb 28-Dec-2014 13:46:46 /Users/geoff/matlab/testing2/KEmode2_G201.txt
224 b 24-Nov-2014 12:30:41 /Users/geoff/matlab/testing2/RealInfo.txt
979 kb 20-Nov-2014 12:08:10 /Users/geoff/matlab/testing2/data.txt
3 kb 24-Nov-2014 09:35:34 /Users/geoff/matlab/testing2/myConv.cpp.txt
341 kb 20-Nov-2014 17:03:56 /Users/geoff/matlab/testing2/myOutput.txt
2 kb 07-Dec-2014 14:21:08 /Users/geoff/matlab/testing2/readString.F.txt
98 b 12-Dec-2014 12:18:03 /Users/geoff/matlab/testing2/test.txt
204 kb 28-Nov-2014 09:13:59 /Users/geoff/matlab/testing2/test2.txt
204 kb 28-Nov-2014 09:14:08 /Users/geoff/matlab/testing2/test3.txt
663 b 10-Nov-2014 08:02:19 /Users/geoff/matlab/testing2/MRSim/Old version docs/DLLs.txt
3 kb 10-Nov-2014 08:02:19 /Users/geoff/matlab/testing2/MRSim/Old version docs/changes.txt
1 kb 10-Nov-2014 08:02:19 /Users/geoff/matlab/testing2/MRSim/Old version docs/disclaimer.txt
3 kb 10-Nov-2014 08:02:19 /Users/geoff/matlab/testing2/MRSim/Old version docs/readme.txt
88 b 10-Nov-2014 08:02:19 /Users/geoff/matlab/testing2/MRSim/Old version docs/version.txt
Note the differences between the above output and the previous example. You may have to experiment with the code to do what you want...
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!