验证文件夹内容

时间:2012-03-27 10:31:55

标签: matlab

我已经

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

我想检查resDir是否包含folder1和folder2,并且它们不是空的 是否有相应的contains(java)或存在函数?

谢谢

2 个答案:

答案 0 :(得分:1)

我认为你所参考的Java函数没有内置的等价物,但是Matlab提供了编写自己所需的所有基础知识而没有太多困难。点击isdirfileparts

的文档

答案 1 :(得分:1)

使用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
相关问题