-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Ability to delete non-empty folder. #8197
Conversation
Not sure i'm a fan of using If you want to implement this i'd say recursively delete files and directories with function deleteDirectory(dir)
local function removeContents(path)
local search = NewFileSearch(path .. "/*")
while search:NextFile() do
local item = path .. "/" .. search:GetFileName()
if search:IsDirectory() then
if search:GetFileName() ~= "." and search:GetFileName() ~= ".." then
removeContents(item)
RemoveDir(item)
end
else
os.remove(item)
end
end
end
removeContents(dir)
RemoveDir(dir)
end |
I'm also not super keen on leveraging A possible alternative if we really want such a powerful primitive is that we could expose |
Could you check it out in your free time ? |
And i have an idea, but i'm not sure about this practice in function deleteDirectory(dir)
local funcs = {}
funcs[false] = os.remove -- delete file
funcs[true] = deleteDirectory -- delete directory
for k, v in pairs(funcs) do
local search = NewFileSearch(dir..'/*', k)
if search then
funcs[k](dir..'/'..search:GetFileName())
while search:NextFile() do
funcs[k](dir..'/'..search:GetFileName())
end
end
end
RemoveDir(dir)
end What do you think about this ? |
I think adding support for recursive folder deletion from the SG side would be the best way to tackle this feature. The method you implemented suffers from the issue that zao mentioned. You're changing the environment from underneath an iterator which is generally not a good idea. https://en.cppreference.com/w/cpp/filesystem/directory_iterator
Imo if you want to stick to the lua side you'd need to first make a list of all the elements to be deleted and then delete them in the right order. You'd probably be looking at a DFS kinda approach. |
Yeah... It seems that things are much more complicated on the LUA side. |
Current implementation of RemoveDir does not allow for removal of direcoties with content. This commit adds a recursive boolean parameter to RemoveDir allowing for recursive removal of directories and their contents. PathOfBuildingCommunity/PathOfBuilding#8197
Fixes #1823 .
Description of the problem being solved:
Added the ability to delete a folder, and all builds stored within the folder.
Steps taken to verify a working solution:
Before screenshot:
After screenshot: