列出Matlab中的可用文件和目录 [英] Listing available files and directories in Matlab

查看:168
本文介绍了列出Matlab中的可用文件和目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Matlab命令窗口(最终在m文件中)递归地列出特定目录中的可用目录和文本文件。我知道像 ls 这样的命令可用,但是我想在以下文件系统结构递归地读取每个文本文件之前,先了解字符串或向量中可用的文本文件:

I would like to list available directories and text files in specific directories recursively in Matlab command window (and ultimately in an m-file). I know commands like ls are available, but I would like to know the text files available in a string or vector before I recursively read each text file in the following file system structure:

主(包含A和B,所有目录)

master (contains A and B, all directories)

A包含A1和A2(所有目录)

A contains A1 and A2 (all directories)

A1包含A11,A12,A13,A14(所有目录)

A1 contains A11, A12, A13, A14 (all directories)

A11包含1.txt,2。 txt,...

A11 contains 1.txt, 2.txt, ...

很高兴听到一些反馈!感谢提前!

Would be great to hear some feedback! Thanks in advance!

推荐答案

您可以使用 DIR 递归。

dir 是第一个和第二个元素分别是当前和父目录的结构,其余的是列出的文件夹的内容。穿过那些如果它是一个目录( dirOutput.isdir == 1 ),请调用 dir 。如果它是一个文件,请将其添加到列表中。

The output of dir is a structure where the first and the second element are current and parent directory, respectively, and the rest are the contents of the folder listed. Step through those. If it's a directory (dirOutput.isdir == 1), call dir on it. If it's a file, add it to the list.

如果您不想自己编码,请查看 Matlab文件交换这里是许多解决方案之一。

If you don't want to code this yourself, have a look around the Matlab File Exchange. Here's one of many solutions.

这篇关于列出Matlab中的可用文件和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆