Hey guys,
I have been looking over and trying many times to use the Lua File System to remove a folder from the Document Directory.
I found the tutorial for the Lua File System, but I can’t figure out how to delete a sub folder of the Documents Directory.
I attempt to set the directory as the documents directory. I then try to set it as the sub folder called “volume 2”, which is the folder I want to fully delete, including all contained files and folder.
Here is my current code:
--Used to delete volume content if requested by the user menuFunctions.deleteVolumeContent = function( event ) if global.volumeToDelete ~= 0 then local lfs = require "lfs"; local doc\_dir = system.DocumentsDirectory local doc\_path = system.pathForFile("", doc\_dir); --Change directory to the Documents directory lfs.chdir( doc\_path ) --Change directory to the volume 2 directory lfs.chdir( lfs.currentdir() .. "/volume2") --Get current path and hold in variable local currentPath = lfs.currentdir() local resultOK, errorMsg; for file in lfs.dir(currentPath) do local theFile = system.pathForFile(file, doc\_dir); if (lfs.attributes(theFile, "mode") ~= "directory") then resultOK, errorMsg = os.remove(theFile); if (resultOK) then print(file.." removed"); else print("Error removing file: "..file..":"..errorMsg); end end end else native.showAlert("Alert", "You must select a volume to delete first.", {"Okay"}) end end
Any help would be much appreciated, I don’t think it should be that hard, I just can’t wrap my head around it.