1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmDirectory.cxx,v $
6 Date: $Date: 2002-03-13 15:25:07 $
7 Version: $Revision: 1.6 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmDirectory.h"
21 // First microsoft compilers
32 #include <sys/types.h>
39 ::Load(const char* name
)
42 size_t n
= strlen(name
);
43 if ( name
[n
- 1] == '/' )
45 buf
= new char[n
+ 1 + 1];
46 sprintf(buf
, "%s*", name
);
50 buf
= new char[n
+ 2 + 1];
51 sprintf(buf
, "%s/*", name
);
53 struct _finddata_t data
; // data of current file
55 // Now put them into the file array
56 size_t srchHandle
= _findfirst(buf
, &data
);
59 if ( srchHandle
== -1 )
67 m_Files
.push_back(data
.name
);
69 while ( _findnext(srchHandle
, &data
) != -1 );
71 return _findclose(srchHandle
) != -1;
76 // Now the POSIX style directory access
78 #include <sys/types.h>
86 ::Load(const char* name
)
88 DIR* dir
= opendir(name
);
95 for (dirent
* d
= readdir(dir
); d
; d
= readdir(dir
) )
97 m_Files
.push_back(d
->d_name
);
112 ::GetFile(size_t index
)
114 if ( index
>= m_Files
.size() )
116 cmSystemTools::Error("Bad index for GetFile on cmDirectory\n", 0);
119 return m_Files
[index
].c_str();