Folder Exists Check in another directory

조회 수: 40 (최근 30일)
Muhammad Abir
Muhammad Abir 2020년 11월 16일
댓글: Muhammad Abir 2020년 11월 16일
I have a code that gives user to select a directory that has image in it. Then the program takes other folders from one step behid. However, the program needs to check if there is any 'Bright' folder exists or not in 'parentFolder' directory. I tried this code but look like ~exist function can only take 'dir'. Is there any way to check folders from parentFolder directory?
Here is my code:
ImageFolder = uigetdir('D:\', 'Select Image Directory');
[parentFolder, thisFolder] = fileparts(ImageFolder);
fileListing = dir(parentFolder); % List of everything: folders and files:
fileListing(ismember( {fileListing.name}, {'.', '..'})) = [];
% Get a list of only the folders
areAFolder = [fileListing.isdir];
% Extract only those items that are folders, not files;
folderListing = fileListing(areAFolder)
if ~exist('Bright', parentFolder)
mkdir('Bright')
end
  댓글 수: 2
Rik
Rik 2020년 11월 16일
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
Muhammad Abir
Muhammad Abir 2020년 11월 16일
Thank you. I'll do that next time

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2020년 11월 16일
Just create the full path name and test agains 'dir'.
bright=fullfile(parentFolder,'Bright');
if ~exist(bright,'dir')
mkdir(bright)
end

추가 답변 (0개)

카테고리

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