Help with Simple Directory Operations

3 次查看(过去 30 天)
Hello,
I have a simple question. I want to first check to see if a folder exists in the working directory. If not, then I create it. I got this part to work.
But now I want to add a second check outside the above check to see if the folder is empty. What is the easiest way todo the last check ?
Thank you!

采纳的回答

per isakson
per isakson 2013-3-21
sad = dir( folder );
any( not( [ sad.isdir ] ) )

更多回答(2 个)

the cyclist
the cyclist 2013-3-21
files = ls('folderName');
isempty(files)
  1 个评论
Jan
Jan 2013-3-21
LS includes an expensive creation of a string, so DIR might be more direct.

请先登录,再进行评论。


Jan
Jan 2013-3-21
if exist(fullfile(cd, 'FolderName'), 'dir') == 0
mkdir(cd, 'FolderName');
end

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by