Filter löschen
Filter löschen

Help with Simple Directory Operations

1 Ansicht (letzte 30 Tage)
Rene
Rene am 21 Mär. 2013
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!

Akzeptierte Antwort

per isakson
per isakson am 21 Mär. 2013
sad = dir( folder );
any( not( [ sad.isdir ] ) )

Weitere Antworten (2)

the cyclist
the cyclist am 21 Mär. 2013
files = ls('folderName');
isempty(files)
  1 Kommentar
Jan
Jan am 21 Mär. 2013
LS includes an expensive creation of a string, so DIR might be more direct.

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 21 Mär. 2013
if exist(fullfile(cd, 'FolderName'), 'dir') == 0
mkdir(cd, 'FolderName');
end

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by