MATLAB's dir function, fullfile function

source

%获取子文件夹
dirList = dir(strPath);  
isSubDir = [dirList(:).isdir]; %# returns logical vector  
nameFolds = {
    
    dirList(isSubDir).name}';  
nameFolds(ismember(nameFolds,{
    
    '.','..'})) = []; 
nSubDir=length(nameFolds);

fileList=dir(fullfile(strcat(strPath,nameFolds{
    
    1},'\*.avi')));  %取第一个文件夹
nFile=length(fileList); 

1. The dir function

files=dir(FilePath)

          Function: Display the files and folders in the FilePath directory

         
Insert picture description here

2. Fullfile function

f=fullfile('dir1', 'dir2', ..., 'filename')

          Function: Use the information of each part of the file to create and synthesize the complete file path, the return value is a path, generally used with dir

Instance

>> FilePath = 'D:\study\dataset';

files = dir(fullfile(FilePath, '\*.xls'));

Return D:\study\datasetall files in the .xls at the end of the path

Guess you like

Origin blog.csdn.net/qq_43657442/article/details/109169789