-
Notifications
You must be signed in to change notification settings - Fork 0
/
pitt_clearWorkingFiles.m
97 lines (67 loc) · 2.67 KB
/
pitt_clearWorkingFiles.m
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function pitt_clearWorkingFiles(baseDir,procStage)
%
% function subs = pitt_getSubs(baseDir)
%
% This funtion will return clear all the working files in each of the
% subjects directories so that processing can continue. A given stage can
% be specified so that other ongoing processes are not affected.
%
% Author: LMP 2012
%
%#ok<*REMFF1>
%% Check INPUT
if notDefined('baseDir')
baseDir = uigetdir(pwd,'Select a Base Directory');
end
if ~exist('procStage','var') || ~isstr(procStage)
procStage = false;
end
%% Return a cell array with the full paths to all subject directories
dirsTextFile = fullfile(baseDir,'.dirs.txt');
cmd = sprintf('ls -1 %s > %s', baseDir, dirsTextFile); system(cmd);
dirs = textread(dirsTextFile,'%s');
cmd = sprintf('rm %s', dirsTextFile); system(cmd);
% Loop over the array and return only those that are directories
for i = sort(1:numel(dirs),'descend');
if isdir(fullfile(baseDir,dirs{i})) && ~strcmp(dirs{i},'logs') && ~strcmp(dirs{i},'freesurfer')
dirs{i} = fullfile(baseDir,dirs{i});
else
dirs(i) = [];
end
end
% Return the total number of directories
n = numel(dirs);
for ii = 1:numel(dirs)
mrddir = fullfile(dirs{ii},'mrDiffusion');
if exist(mrddir,'dir')
% Remove the working files
if ~procStage
delete(fullfile(mrddir,'.working*'));
else
switch lower(procStage)
case 'anatproc'
if exist(fullfile(mrddir,'.workinganatproc'),'file');
delete(fullfile(mrddir,'.workinganatproc'));
end
case 'dtiproc'
if exist(fullfile(mrddir,'.workingdtiproc'),'file')
delete(fullfile(mrddir,'.workingdtiproc'));
end
case 'freeseg'
if exist(fullfile(mrddir,'.workingfreeseg'),'file')
delete(fullfile(mrddir,'.workingfreeseg'));
end
case {'wbfibertrack', 'wholebrainfibertrack'}
if exist(fullfile(mrddir,'.workingwbfibertrack'),'file')
delete(fullfile(mrddir,'.workingwbfibertrack'));
end
case {'morifibertrack', 'mori'}
if exist(fullfile(mrddir,'.workingmorifibertrack'),'file')
delete(fullfile(mrddir,'.workingmorifibertrack'));
end
end
end
end
end
disp(' Working files cleared.');
return