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?

 Accepted Answer

My attached demo will do that. Just change the file pattern to *.pm3

4 Comments

thanks a lot.i want to use the function in C# , written in matlab so ..?
You can ask in a C# forum for C# code, or else compile the MATLAB code into a DLL.
Can we save these fullfileNames int a list. to rturn using function?????
Yes. You can make a function that takes a top level folder and then returns a list of all mp3 files within that tree.

Sign in to comment.

More Answers (1)

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

thanks for your attention sir.i want to return the file names with full path.
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.
thanks. is it for one directory ? how to go through with subfolders? kindly guide me.
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...

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!