Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3291,6 +3291,10 @@ unless otherwise noted.

Removes a directory. Only works if the directory is already empty.

* ``dfhack.filesystem.rmdir_recursive(path)``

Removes a directory and all of its contents recursively.

* ``dfhack.filesystem.mtime(path)``

Returns the modification time (in seconds) of the file or directory
Expand Down
1 change: 1 addition & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,6 +3338,7 @@ static const LuaWrapper::FunctionReg dfhack_filesystem_module[] = {
WRAPM(Filesystem, mkdir),
WRAPM(Filesystem, mkdir_recursive),
WRAPM(Filesystem, rmdir),
WRAPM(Filesystem, rmdir_recursive),
WRAPM(Filesystem, exists),
WRAPM(Filesystem, isfile),
WRAPM(Filesystem, isdir),
Expand Down
1 change: 1 addition & 0 deletions library/include/modules/Filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace DFHack {
// returns true on success or if directory already exists
DFHACK_EXPORT bool mkdir_recursive(std::filesystem::path path) noexcept;
DFHACK_EXPORT bool rmdir(std::filesystem::path path) noexcept;
DFHACK_EXPORT bool rmdir_recursive(std::filesystem::path path) noexcept;
DFHACK_EXPORT bool stat(std::filesystem::path path, std::filesystem::file_status& info) noexcept;
DFHACK_EXPORT bool exists(std::filesystem::path path) noexcept;
DFHACK_EXPORT bool isfile(std::filesystem::path path) noexcept;
Expand Down
13 changes: 13 additions & 0 deletions library/modules/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ bool Filesystem::rmdir (std::filesystem::path path) noexcept
}
}

bool Filesystem::rmdir_recursive (std::filesystem::path path) noexcept
{
try
{
std::filesystem::remove_all(path);
return true;
}
catch (std::filesystem::filesystem_error&)
{
return false;
}
}

bool Filesystem::stat (std::filesystem::path path, std::filesystem::file_status &info) noexcept
{
try
Expand Down