File: batchstatselect.pas

package info (click to toggle)
mricron 0.20140804.1~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 13,508 kB
  • sloc: pascal: 114,876; sh: 49; makefile: 35
file content (82 lines) | stat: -rwxr-xr-x 2,489 bytes parent folder | download | duplicates (4)
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
unit batchstatselect;
{$H+}
interface

uses
  Classes, SysUtils,StrUtils, define_types, Dialogs;

procedure GetFilesInDir (lDefaultFolder: string; var lFilenames: TStrings);

implementation

function IsStatHdr(lStr: string): boolean;
//detects 'spmT_000*.hdr and  zstat*.nii.gz
//requires StrUtils
var
   lExt: string;
begin
     result := false;
     if not IsExtNIFTIHdr(lStr) then
      exit;
     if AnsiContainsText(lStr, 'spmT_') or  AnsiContainsText(lStr, pathdelim+'zstat') then
      result := true;
end;

procedure FindNIIhdrRecursive (var lFolderNameIn: string; var lStringList : TStrings);
var
 len: integer;
 lFolderName,lNewDir,lNewName,lExt: String;
 lSearchRec: TSearchRec;
begin
 lFolderName := lFolderNameIn;
 if not DirExists (lFolderName) then begin
     lFolderName := ExtractFileDir(lFolderName);
 end;
 if (length(lFolderName) > 1) and (lFolderName[length(lFolderName)] <> PathDelim) then
    lNewDir := lFolderName+PathDelim;
 if DirExists (lNewDir) then begin
{$IFDEF UNIX}
 if FindFirst(lNewDir+'*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
{$ELSE}
 if FindFirst(lNewDir+'*.*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
{$ENDIF}
    repeat
      lNewName := lNewDir+lSearchRec.Name;
      if  (lSearchRec.Name = '.') or (lSearchRec.Name = '..') then
        //current or parent folder - do nothing
      else if DirExists(lNewName) then
              FindNIIhdrRecursive (lNewName, lStringList)
      else if  IsStatHdr(lNewName)  then
              lStringList.Add(lNewName);
    until (FindNext(lSearchRec) <> 0);
   end; //if findfirst
   FindClose(lSearchRec);
 end;//Direxists
end;

procedure FilterForText (lRequiredText: string; var lFilenames: TStrings);
var
  i,len: integer;
begin
  len := lFilenames.Count;
  if (length(lRequiredText) < 1) or (len < 1) then
    exit;
  for i := len-1 downto 0 do
    if not AnsiContainsText(lFilenames[i], lRequiredText)  then
      lFilenames.Delete(i);
end;

procedure GetFilesInDir (lDefaultFolder: string; var lFilenames: TStrings);
var
  lParentDir,lFilter : string;
begin
     lParentDir := GetDirPrompt (lDefaultFolder);
     FindNIIhdrRecursive(lParentDir,lFilenames);
     lFilter := '.gfeat';
     InputQuery('Filter data', 'Filter for statistical maps [e.g. ''.gfeat'' will only analyze files with this in their path. Set to blank to analyze all files',lFilter);
     FilterForText(lFilter,lFilenames);
end;


end.