필터 지우기
필터 지우기

Help with Simple Directory Operations

조회 수: 1 (최근 30일)
Rene
Rene 2013년 3월 21일
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