Skip to content

Commit

Permalink
Fixed up the builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
ineed bots committed Dec 3, 2023
1 parent 4843c61 commit f0c9534
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ All files will be closed upon GSC restart (map_restart or fast_restart or missio
// close the file
```

* `<array of strings> FS_ListFiles(<folder string>, <recurse bool>(optional))` Returns a list of files inside of the folder given. Can recurse if set to `true`.
* `<array of strings> FS_ListFiles(<folder string>)` Returns a list of files inside of the folder given.
```gsc
files = FS_ListFiles("testfolder/");
for (i = 0; i < files.size; i++)
{
file - files[i]; // will be "testfolder/<filename>"
file = files[i]; // will be "testfolder/<filename>"
// do something with the filename
}
Expand Down
7 changes: 4 additions & 3 deletions src/component/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace fileio
{
if (fpath.empty())
{
return false;
return true;
}

constexpr static std::array bad_strings { R"(..)", R"(../)", R"(..\)" };
Expand Down Expand Up @@ -404,15 +404,16 @@ namespace fileio

gsc::function::add("fs_listfiles", []()
{
auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER));
std::string dir = game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER);
auto fpath = build_base_path(dir);

int numfiles;
auto* files = game::FS_ListFiles(fpath.c_str(), "", game::FS_LIST_ALL, &numfiles);

game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER);
for (int i = 0; i < numfiles; i++)
{
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, files[i]);
game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, (dir + "/" + files[i]).c_str());
game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER);
}

Expand Down

0 comments on commit f0c9534

Please sign in to comment.