Alternative to using "unix(sprintf('ls %s/*/*/*.out',pathname))" ?
Mostrar comentarios más antiguos
I am using the following command to gather a list of files with the same extension (*.out) down a couple directories:
[~,List] = unix(sprintf('ls %s/*/*/*.out',pathname));
This works for what I am doing when I run from Matlab, but as soon as I make a standalone executable for any .m file that has a "unix('ls something')" it will not work. In the past I was able to get around this by using Matlab's "dir" function, but that only works if I have the following situation:
DirResult = dir(sprintf('%s/*.out',pathname));
not for
DirResult = dir(sprintf('%s/*/*.out',pathname));
And I can't use:
List = ls(sprintf('%s/*/*/*.out',pathname));
because if the path with wild cards does not exist, then I get an error (instead of allowing me to deal with the fact that it doesn't exist in a more convenient way).
Any ideas or am I doing something "silly"?
Respuesta aceptada
Más respuestas (2)
Wannabegeek
el 8 de Abr. de 2012
I found your question after reading a great answer you gave about fft in MATLAB...thanks, so to attempt a return on the favor I have some ideas about an answer for you.
I run MATLAB in a linux environment myself and just use:
dir(path_with_bash_wildcards)
I don't see any reason to use 'unix' with 'dir' unless I've missed something.
!find root_path -type f -iname *.out > file_list
file_list = load('file_list.txt');
hope that helps... wbg
Walter Roberson
el 8 de Abr. de 2012
1 voto
Use dir(pathname) and check the isdir() field to find the first level of directories under the path. For each of those directories, dir() [pathname '/' directoryname1] and check the isdir() field, to find the second level of directories. And in each resulting second level directory, dir() [pathname '/' directoryname1 '/' directoryname2 '/*.out') -- and just to be safe, use isdir() and this time throw away any of the *.out that happened to be directories.
There is a File Exchange contribution that will do recursive matches and process each match.
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!