3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 05:18:44 +00:00
z3/src/test/for_each_file.cpp
Nikolaj Bjorner 2b2f193f2b remove dependency on ARRAYSIZE for issue #1616
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-08-15 22:26:14 -07:00

81 lines
1.6 KiB
C++

/*++
Copyright (c) 2006 Microsoft Corporation
Module Name:
foreach_file.cpp
Abstract:
Traverse files in a directory that match a given suffix.
Apply a method to each of the files.
Author:
Nikolaj Bjorner (nbjorner) 2006-11-3.
Revision History:
--*/
#ifdef _WINDOWS
#include <string>
#include <windows.h>
#include <strsafe.h>
#include "util/util.h"
#include "test/for_each_file.h"
bool for_each_file(for_each_file_proc& proc, const char* base, const char* suffix)
{
std::string pattern(base);
pattern += "\\";
pattern += suffix;
char buffer[MAX_PATH];
WIN32_FIND_DATAA data;
HANDLE h = FindFirstFileA(pattern.c_str(),&data);
while (h != INVALID_HANDLE_VALUE) {
StringCchPrintfA(buffer, Z3_ARRAYSIZE(buffer), "%s\\%s", base, data.cFileName);
if (!proc(buffer)) {
return false;
}
if (!FindNextFileA(h,&data)) {
break;
}
}
//
// Now recurse through sub-directories.
//
pattern = base;
pattern += "\\*";
h = FindFirstFileA(pattern.c_str(),&data);
while (h != INVALID_HANDLE_VALUE) {
if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
data.cFileName[0] != '.'
){
std::string subdir(base);
subdir += "\\";
subdir += data.cFileName;
if (!for_each_file(proc, subdir.c_str(), suffix)) {
return false;
}
}
if (!FindNextFileA(h,&data)) {
break;
}
}
return true;
};
#endif