]> cygwin.com Git - cygwin-apps/setup.git/blame - find.cc
2002-07-15 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / find.cc
CommitLineData
23c9e63c 1/*
b401ef47 2 * Copyright (c) 2002, Robert Collins.
23c9e63c
DD
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>
b401ef47 13 * Rewritten by Robert Collins <rbtcollins@hotmail.com>
23c9e63c
DD
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
b24c88b3
RC
20#if 0
21static const char *cvsid =
22 "\n%%% $Id$\n";
23#endif
8507f105 24
b401ef47 25#include "find.h"
23c9e63c 26#include "win32.h"
23c9e63c
DD
27#include <stdlib.h>
28
b401ef47 29//#include "port.h"
23c9e63c 30
3c054baf 31#include "String++.h"
b401ef47
RC
32#include "FindVisitor.h"
33#include <stdexcept>
34
35Find::Find(String const &starting_dir) : _start_dir (starting_dir), h(INVALID_HANDLE_VALUE)
36{
37}
3c054baf 38
b401ef47
RC
39Find::~Find()
40{
41 if (h != INVALID_HANDLE_VALUE && h)
42 FindClose (h);
43}
23c9e63c 44
b401ef47
RC
45void
46Find::accept (FindVisitor &aVisitor)
23c9e63c
DD
47{
48 WIN32_FIND_DATA wfd;
b401ef47
RC
49 if (_start_dir.size() > _MAX_PATH)
50 throw new length_error ("starting dir longer than _MAX_PATH");
23c9e63c 51
b401ef47 52 h = FindFirstFile ((_start_dir + "/*").cstr_oneuse(), &wfd);
23c9e63c
DD
53
54 if (h == INVALID_HANDLE_VALUE)
b401ef47
RC
55 return;
56
57 String basePath = _start_dir + "/";
23c9e63c 58
b24c88b3
RC
59 do
60 {
61 if (strcmp (wfd.cFileName, ".") == 0
62 || strcmp (wfd.cFileName, "..") == 0)
63 continue;
23c9e63c 64
b401ef47
RC
65 /* TODO: make a non-win32 file and dir info class and have that as the
66 * visited node
67 */
b24c88b3 68 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
b401ef47 69 aVisitor.visitDirectory (basePath, &wfd);
b24c88b3 70 else
b401ef47 71 aVisitor.visitFile (basePath, &wfd);
b24c88b3
RC
72 }
73 while (FindNextFile (h, &wfd));
23c9e63c 74}
This page took 0.037484 seconds and 5 git commands to generate.