]>
cygwin.com Git - cygwin-apps/setup.git/blob - find.cc
2 * Copyright (c) 2002, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
13 * Rewritten by Robert Collins <rbtcollins@hotmail.com>
17 /* The purpose of this file is to doa recursive find on a given
18 directory, calling a given function for each file found. */
21 static const char *cvsid
=
27 #include "FindVisitor.h"
32 Find::Find(const std::string
& starting_dir
)
33 : h(INVALID_HANDLE_VALUE
)
35 _start_dir
= starting_dir
;
36 int l
= _start_dir
.size ();
38 /* Ensure that _start_dir has a trailing slash if it doesn't already. */
39 if (l
< 1 || (starting_dir
[l
- 1] != '/' && starting_dir
[l
- 1] != '\\'))
45 if (h
!= INVALID_HANDLE_VALUE
&& h
)
50 Find::accept (FindVisitor
&aVisitor
)
53 if (_start_dir
.size() > MAX_PATH
)
54 throw new length_error ("starting dir longer than MAX_PATH");
56 h
= FindFirstFile ((_start_dir
+ "*").c_str(), &wfd
);
58 if (h
== INVALID_HANDLE_VALUE
)
63 if (strcmp (wfd
.cFileName
, ".") == 0
64 || strcmp (wfd
.cFileName
, "..") == 0)
67 /* TODO: make a non-win32 file and dir info class and have that as the
70 if (wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
71 aVisitor
.visitDirectory (_start_dir
, &wfd
);
73 aVisitor
.visitFile (_start_dir
, &wfd
);
75 while (FindNextFile (h
, &wfd
));
This page took 0.03752 seconds and 5 git commands to generate.