matlab - 验证文件夹内容

标签 matlab

我已经

resDir = C:\temp\source\
                --------\folder1
                --------\folder2
                --------\file.txt
%list the content of resDir
list = ls(resDir);

我想检查 resDir 是否包含folder1和folder2并且它们不为空 是否有等效的 contains(java) 或 exit 函数?

谢谢

最佳答案

使用 EXIST 函数检测特定文件夹是否存在。

函数 DIR 返回目录中所有对象的结构体数组。空文件夹将仅包含 2 个对象:.(当前目录)和 ..(根目录)。

resDir = 'C:\temp\source\';
folder = 'folder1';
folderfull = fullfile(resDir,folder); %# full path to the folder
if exist(folderfull,'dir')
    foldercontent = dir(folderfull);
    if numel(foldercontent) > 2
        %# folder exists and is not empty
    end
end

关于matlab - 验证文件夹内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9887818/

相关文章:

matlab - 使用 MATLAB 函数 block 在 Simulink 中生成随机数

matlab - 使用 MATLAB 在图中查找邻居的邻居

matlab - 使用 subplot-command 更改已有的包含线条的子图以绘制更多线条

matlab - 如何在matlab中屏蔽图像的一部分?

arrays - 如何使用 MATLAB 返回包含 list1 和 list2 中的元素的列表

matlab - 使用 scatter3 用 3D 立方体填充空间

matlab - Matlab中手动排列字符串元胞数组的用户控制功能

matlab - Matlab c++中OpenCV cvtColor出错

arrays - 在 matlab 中从 3 列表创建网格

matlab - 在 Matlab 中使用 svmtrain 内存不足