我已经
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/