Skip to content

Commit a93cf50

Browse files
committed
Draft recursive directory iteration
In check-mode, we only want to iterate `.sfv` files technically so there will need to be some filtering. Maybe there is an implicit filtering argument can be added that defaults to `.sfv` when in check mode. This could also add functionality where a bare `./qCheck -c` command can automatically glob `.sfv` files in the current working directory.
1 parent 9665e2e commit a93cf50

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

source/main.cpp

+30-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@
1010

1111
#include <qCheck.hpp>
1212

13+
void ProcessInputPath(Settings& CurSettings, const std::filesystem::path& Path)
14+
{
15+
if( !std::filesystem::exists(Path) )
16+
{
17+
std::fprintf(stderr, "Path does not exist: %s\n", Path.c_str());
18+
return;
19+
}
20+
std::error_code CurError;
21+
// Regular files only, for now, other files will be specially handled
22+
// later
23+
if( std::filesystem::is_regular_file(Path, CurError) )
24+
{
25+
CurSettings.InputFiles.emplace_back(Path);
26+
}
27+
else if(
28+
CurSettings.Recursive && std::filesystem::is_directory(Path, CurError) )
29+
{
30+
for( const std::filesystem::directory_entry& DirectoryEntry :
31+
std::filesystem::recursive_directory_iterator(Path) )
32+
{
33+
ProcessInputPath(CurSettings, DirectoryEntry.path());
34+
}
35+
}
36+
else
37+
{
38+
std::fprintf(stderr, "Error opening path: %s\n", Path.c_str());
39+
}
40+
}
41+
1342
int main(int argc, char* argv[])
1443
{
1544
Settings CurSettings = {};
@@ -68,22 +97,7 @@ int main(int argc, char* argv[])
6897
for( std::intmax_t i = 0; i < argc; ++i )
6998
{
7099
const std::filesystem::path CurPath(argv[i]);
71-
if( !std::filesystem::exists(CurPath) )
72-
{
73-
std::fprintf(stderr, "File does not exist: %s\n", argv[i]);
74-
continue;
75-
}
76-
std::error_code CurError;
77-
// Regular files only, for now, other files will be specially handled
78-
// later
79-
if( std::filesystem::is_regular_file(CurPath, CurError) )
80-
{
81-
CurSettings.InputFiles.emplace_back(CurPath);
82-
}
83-
else
84-
{
85-
std::fprintf(stderr, "Error opening file: %s\n", argv[i]);
86-
}
100+
ProcessInputPath(CurSettings, CurPath);
87101
}
88102

89103
return CurSettings.Check ? CheckSFV(CurSettings) : GenerateSFV(CurSettings);

0 commit comments

Comments
 (0)