3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 OS-specific functions to assist in finding files in
26 // #include <io.h> // for _chmod()
30 // #include <errno.h> // for errno
55 FIND_FILE_CALLBACK Callback
58 /*****************************************************************************/
63 FIND_FILE_CALLBACK Callback
68 Find files of a given name under a root directory
71 RootDirectory - base directory -- look in this directory and
72 all its subdirectories for files matching FileMask.
73 FileMask - file mask of files to find
74 Callback - function to call for each file found
80 char FullPath
[MAX_PATH
];
82 // If RootDirectory is relative, then append to cwd.
84 if (isalpha (RootDirectory
[0]) && (RootDirectory
[1] == ':')) {
85 strcpy (FullPath
, RootDirectory
);
88 // Get current working directory
90 if (_getcwd (FullPath
, sizeof (FullPath
)) == NULL
) {
91 Error (NULL
, 0, 0, "failed to get current working directory", NULL
);
95 // Append the relative path they passed in
97 if (FullPath
[strlen (FullPath
) - 1] != '\\') {
98 strcat (FullPath
, "\\");
101 strcat (FullPath
, RootDirectory
);
104 if (FullPath
[strlen (FullPath
) - 1] == '\\') {
105 FullPath
[strlen (FullPath
) - 1] = 0;
108 // Process the directory
110 return ProcessDirectory (FullPath
, FileMask
, Callback
);
118 FIND_FILE_CALLBACK Callback
123 Process a directory to find all files matching a given file mask
126 RootDirectory - base directory -- look in this directory and
127 all its subdirectories for files matching FileMask.
128 FileMask - file mask of files to find
129 Callback - function to call for each file found
136 WIN32_FIND_DATA FindData
;
137 char TempName
[MAX_PATH
];
139 Handle
= INVALID_HANDLE_VALUE
;
141 // Concatenate the filemask to the directory to create the full
142 // path\mask path name.
144 strcpy (TempName
, RootDirectory
);
145 strcat (TempName
, "\\");
146 strcat (TempName
, FileMask
);
147 memset (&FindData
, 0, sizeof (FindData
));
148 Handle
= FindFirstFile (TempName
, &FindData
);
149 if (Handle
!= INVALID_HANDLE_VALUE
) {
151 if ((FindData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) == 0) {
152 strcpy (TempName
, RootDirectory
);
153 strcat (TempName
, "\\");
154 strcat (TempName
, FindData
.cFileName
);
155 if (Callback (TempName
) != 0) {
159 } while (FindNextFile (Handle
, &FindData
));
162 if (Handle
!= INVALID_HANDLE_VALUE
) {
164 Handle
= INVALID_HANDLE_VALUE
;
167 // Now create a *.* file mask to get all subdirectories and recursive call this
168 // function to handle each one found.
170 strcpy (TempName
, RootDirectory
);
171 strcat (TempName
, "\\*.*");
172 memset (&FindData
, 0, sizeof (FindData
));
173 Handle
= FindFirstFile (TempName
, &FindData
);
175 // Loop until no more files/directories
177 if (Handle
!= INVALID_HANDLE_VALUE
) {
179 if (FindData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) {
181 // Make sure it's not "." or ".."
183 if ((strcmp (FindData
.cFileName
, ".") != 0) && (strcmp (FindData
.cFileName
, "..") != 0)) {
185 // Found a valid directory. Put it all together and make a recursive call
188 strcpy (TempName
, RootDirectory
);
189 strcat (TempName
, "\\");
190 strcat (TempName
, FindData
.cFileName
);
191 if (ProcessDirectory (TempName
, FileMask
, Callback
) != 0) {
196 } while (FindNextFile (Handle
, &FindData
));
203 if (Handle
!= INVALID_HANDLE_VALUE
) {