1 mike 1.4 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.4 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "Destroyer.h"
30 #include "Dir.h"
31 #include "Exception.h"
32
33 PEGASUS_NAMESPACE_BEGIN
34
35 #include <io.h>
36 #include <direct.h>
37
38 struct DirRep
39 {
40 long file;
41 struct _finddata_t findData;
42 };
43 mike 1.4
44 Dir::Dir(const String& path)
45 {
46 ArrayDestroyer<char> p(strcat(path.allocateCString(2), "/*"));
47 _rep = new DirRep;
48 _rep->file = _findfirst(p.getPointer(), &_rep->findData);
49
50 if (_rep->file == -1)
51 {
52 _more = false;
53 throw CannotOpenDirectory(path);
54 }
55 else
56 _more = true;
57 }
58
59 Dir::~Dir()
60 {
61 if (_rep->file != -1)
62 _findclose(_rep->file);
63
64 mike 1.4 delete _rep;
65 }
66
67 const char* Dir::getName() const
68 {
69 return _rep->findData.name;
70 }
71
72 void Dir::next()
73 {
74 if (!_more)
75 return;
76
77 _more = _findnext(_rep->file, &_rep->findData) == 0;
78 }
79
80 PEGASUS_NAMESPACE_END
|