You have a few errors in your function, and you don’t need to change directory for this to work.
Look at the following modified code:
menuFunctions.deleteVolumeContent = function( event ) if global.volumeToDelete ~= 0 then local lfs = require "lfs"; local doc\_dir = system.DocumentsDirectory; local doc\_path = system.pathForFile("volume2", doc\_dir); local resultOK, errorMsg; --remove files from directory for file in lfs.dir(doc\_path) do local theFile = doc\_path.."/"..file; 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 -- -- remove directory -- resultOK, errorMsg = os.remove(doc\_path); -- -- if (resultOK) then -- print(doc\_path.." removed"); -- else -- print("Error removing file: "..doc\_path..":"..errorMsg); -- end else native.showAlert("Alert", "You must select a volume to delete first.", {"Okay"}) end end
This will delete the contents of your ‘volume2’ directory.
If you also want to delete ‘volume2’ after the files are removed, just un-comment the block at the end.