urldir.m

来自「This code can parse any image in matlab.」· M 代码 · 共 67 行

M
67
字号
function files = urldir(page, tag)
%
% Lists the files within a URL
%
% Collecion of folders:
% files = urldir(page, 'DIR')
% Collection of files:
% files = urldir(page, 'TXT')

% Created: A. Torralba, 2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LabelMe, the open annotation tool
% Contribute to the database by labeling objects using the annotation tool.
% 
% CSAIL, MIT
% 2006
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin == 1
    tag = '[dir]';
    tag = '/'
else
    tag = lower(tag);
    if strcmp(tag, 'dir')
        tag = '/';
    end
    if strcmp(tag, 'txt')
        tag = 'xml';
    end
    if strcmp(tag, 'img')
        tag = 'jpg';
    end
    if strcmp(tag, 'png')
        tag = 'png';
    end
end

nl = length(tag);
nfiles = 0;
files = [];

% Read page
page = strrep(page, '\', '/');
webpage = urlread(page);

% Parse page
j1 = findstr(lower(webpage), '<a href="');
j2 = findstr(lower(webpage), '</a>');
Nelements = length(j1);
if Nelements>0
    for f = 1:Nelements
        % get HREF element
        chain = webpage(j1(f):j2(f));
        jc = findstr(lower(chain), '">');
        chain = deblank(chain(10:jc(1)-1));
        
        % check if it is the right type
        if strcmp(chain(end-nl+1:end), tag)
            nfiles = nfiles+1;
            chain = strrep(chain, '%20', ' '); % replace space character
            files(nfiles).name = chain;
            files(nfiles).bytes = 1;        
        end
   end    
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?