File size: 1,474 Bytes
d4035c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function ADMINrenamefolder(HOMEANNOTATIONS, Folder)
%
% Writes in the folder field of the xml file the nane of the folder in
% which the annotation files are.
%
% This script is useful when moving annotation files into other folders
% manually. This function guaratees consistency.


% Create list of folders
if nargin == 1
    folders = genpath(HOMEANNOTATIONS);
    h = [findstr(folders,  pathsep)];
    h = [0 h];
    Nfolders = length(h)-1;
    for i = 1:Nfolders
        tmp = folders(h(i)+1:h(i+1)-1);
        tmp = strrep(tmp, HOMEANNOTATIONS, ''); tmp = tmp(2:end);
        Folder{i} = tmp;
    end
end

Nfolders = length(Folder);

for m = 1:Nfolders
    annotationfolder = strrep(Folder{m}, '\', '/');
    files = dir(fullfile(HOMEANNOTATIONS, annotationfolder, '*.xml'));

    Nfiles = length(files);
    for i = 1:Nfiles
        v = loadXML(fullfile(HOMEANNOTATIONS, annotationfolder, files(i).name));
        if isfield(v.annotation, 'folder')
            if ~strcmp(v.annotation.folder,annotationfolder)
                v.annotation.folder = annotationfolder;
                writeXML(fullfile(HOMEANNOTATIONS, annotationfolder, files(i).name), v);
                
                disp(sprintf('%d, %d) %s, changed', m,i,files(i).name))
            else
                disp(sprintf('%d, %d) %s, already goo', m,i,files(i).name))
            end
        else
            disp(sprintf('%d, %d) %s, no folder field', m,i,files(i).name))
        end
    end
end