Folder Exists Check in another directory
26 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!