]> cygwin.com Git - cygwin-apps/setup.git/blob - find.cc
2002-07-02 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / find.cc
1 /*
2 * Copyright (c) 2002, Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by DJ Delorie <dj@cygnus.com>
13 * Rewritten by Robert Collins <rbtcollins@hotmail.com>
14 *
15 */
16
17 /* The purpose of this file is to doa recursive find on a given
18 directory, calling a given function for each file found. */
19
20 #if 0
21 static const char *cvsid =
22 "\n%%% $Id$\n";
23 #endif
24
25 #include "find.h"
26 #include "win32.h"
27 #include <stdlib.h>
28
29 //#include "port.h"
30
31 #include "String++.h"
32 #include "FindVisitor.h"
33 #include <stdexcept>
34
35 Find::Find(String const &starting_dir) : _start_dir (starting_dir), h(INVALID_HANDLE_VALUE)
36 {
37 }
38
39 Find::~Find()
40 {
41 if (h != INVALID_HANDLE_VALUE && h)
42 FindClose (h);
43 }
44
45 void
46 Find::accept (FindVisitor &aVisitor)
47 {
48 WIN32_FIND_DATA wfd;
49 if (_start_dir.size() > _MAX_PATH)
50 throw new length_error ("starting dir longer than _MAX_PATH");
51
52 h = FindFirstFile ((_start_dir + "/*").cstr_oneuse(), &wfd);
53
54 if (h == INVALID_HANDLE_VALUE)
55 return;
56
57 String basePath = _start_dir + "/";
58
59 do
60 {
61 if (strcmp (wfd.cFileName, ".") == 0
62 || strcmp (wfd.cFileName, "..") == 0)
63 continue;
64
65 /* TODO: make a non-win32 file and dir info class and have that as the
66 * visited node
67 */
68 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
69 aVisitor.visitDirectory (basePath, &wfd);
70 else
71 aVisitor.visitFile (basePath, &wfd);
72 }
73 while (FindNextFile (h, &wfd));
74 }
This page took 0.036078 seconds and 5 git commands to generate.