• Matlab批量获取子文件夹与文件名


    批量得到父文件夹下所有子文件夹的路径的MATLAB函数。
    function [SubFolders] = GetFolders(ParentFolder)
    %GetFolders 
    % 函数功能为获取父文件夹下所有子文件夹的路径
    % 函数的输入为ParentFolder:父文件夹路径。eg: 'D:Program Files'
    % 函数的输出为SubFolders:子文件夹路径。为一个元胞数组,eg: {'D:Program FilesFileZilla FTP Clientdocs'}
     
    SubFolderNames = dir(ParentFolder);
    for i=1:length(SubFolderNames)
            if( isequal( SubFolderNames( i ).name, '.' )||...
            isequal( SubFolderNames( i ).name, '..')||...
            ~SubFolderNames( i ).isdir) % 如果不是目录则跳过
                continue;
            end
            SubFolder(i).SubFolderName = fullfile( ParentFolder, SubFolderNames( i ).name );
    end
    
    temp = {SubFolder.SubFolderName};
    idx = cellfun(@(x)~isempty(x),temp,'UniformOutput',true); % 利用cellfun函数得到元胞数组中所有非空元素的下标
    SubFolders = temp(idx);
    
    end
    

    批量得到文件夹下某一类型的所有文件名的MATLAB函数。

    function [FileNames] = GetFileNames(Path,Format)
    % GetFileNames 
    % 函数的功能为获得某一路径下,某种格式所有文件名
    % 函数的输入1为Path,要获取的路径。eg: 'D:Program FilesFileZilla FTP Clientdocs'
    % 函数的输入2为Format,要获取路径的文件格式。eg: '*.txt','*.docx','*.png'
    
    fileFolder=fullfile(Path); 
    dirOutput=dir(fullfile(fileFolder,Format));
    FileNames={dirOutput.name};
    
    end
    

    利用上面两个函数,结合实际问题,利用循环便可实现文件夹嵌套情况下的文件名批量获取



  • 相关阅读:
    qiankun 报错:Target container with #container not existed while xxx mounting!
    promise加载队列实现
    promise 封装定时器
    关于promise
    节流防抖
    箭头函数特点
    this
    手写apply
    手写call
    手写bind函数
  • 原文地址:https://www.cnblogs.com/yhpan/p/11298219.html
Copyright © 2020-2023  润新知