Unknown File/Folder in directory
10 views (last 30 days)
Show older comments
HI, I'm one of the enw users of Matlab.
I'm Having some problem in folder and sub folder reading......
Look at this Code....
Name = '.\train20X20\'
Main_File = dir(fullfile(Name));
Normal access to a folder, but this folder has 34 sub folder in it but when I compile this line, on the (Workspace) Tab the variable Main_File shows that there are 36 folders in it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/497792/image.png)
What does this mean, I dont Understand.
In the Main folder there are 34 subfolders having 10 images each. what is wrong.
after that when i try to make a loop to access the subfolder using there names it shows an error message.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/497797/image.png)
I tried bothg with Curly Brackets and Small Brackets but the same message appeared.
Few Monthes Earliar i worked on something similar, the function worked perfectly but this time it's not working i dont know what wrong.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/497802/image.png)
1 Comment
Accepted Answer
per isakson
on 23 Jan 2021
Edited: per isakson
on 24 Jan 2021
"What does this mean, I dont Understand." I assume that you refer to 34 and 36, respectively.
Main_File is a struct array with one element for each file/folder in the folder, "\train20X20\". And in addition two elements (on Windows at least), which represent the folder itself and its parent folder.
>> Main_File(1:2).name
ans =
'.'
ans =
'..'
"using there names it shows an error message" Main_File is not a name, it's a struct. Main_File.name and Main_File.folder are names.
See: Debug a MATLAB Program and then step through the code line by line and inspect the values of the variables.
A different approach (added later)
"Main folder there are 34 subfolders having 10 images each" If the main folder doesn't contain anything else and you don't need to distinguish between the images of the different subfolders.
%%
MainFolder = 'something';
sad = dir( fullfile( MainFolder, '**', '*.jpg' ) );
for jj = 1 : numel(sad)
ffs = fullfile( sad(jj).folder, sad(jj).name );
image_matrix = imread( ffs );
% your code
end
3 Comments
Image Analyst
on 23 Jan 2021
if strcmp(image_path, '.') || strcmp(image_path, '..')
continue; % Skip to bottom of loop.
end
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!