Help with Simple Directory Operations

3 views (last 30 days)
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!

Accepted Answer

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

More Answers (2)

the cyclist
the cyclist on 21 Mar 2013
files = ls('folderName');
isempty(files)
  1 Comment
Jan
Jan on 21 Mar 2013
LS includes an expensive creation of a string, so DIR might be more direct.

Sign in to comment.


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

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!