Command to delete a directory and all its files

Someone knows if there is a unique command that deletes a directory and all files included in it?

Now I am having to delete each files one by one and after delete their parent directory.

Thanks,

rsc [import]uid: 181011 topic_id: 33640 reply_id: 333640[/import]

I had a look a while ago and could not find one. I use this code to do the trick

[lua]deleteDir = function(dirToDel)
–returns false if failed other wise returns true
local docPath = system.pathForFile( “”, system.DocumentsDirectory )
if( lfs.chdir( docPath )) then-- returns true on success
–delete all the files in the dir
for myFile in lfs.dir(docPath…"/"…dirToDel) do
– file is the current file or directory name
if(myFile ~= “.” and myFile ~= “…”) then
os.remove(docPath…"/"… dirToDel…"/"…myFile)
end
end
if(lfs.rmdir(dirToDel)) then
return true
else
return false
end
else
return false
end
end[/lua] [import]uid: 169392 topic_id: 33640 reply_id: 133759[/import]

Thanks. I am almost finish my own code here… it is similar to yours but I am also making it to erase subdirectories as well. I post here later if it works :slight_smile: [import]uid: 181011 topic_id: 33640 reply_id: 133768[/import]

I had a look a while ago and could not find one. I use this code to do the trick

[lua]deleteDir = function(dirToDel)
–returns false if failed other wise returns true
local docPath = system.pathForFile( “”, system.DocumentsDirectory )
if( lfs.chdir( docPath )) then-- returns true on success
–delete all the files in the dir
for myFile in lfs.dir(docPath…"/"…dirToDel) do
– file is the current file or directory name
if(myFile ~= “.” and myFile ~= “…”) then
os.remove(docPath…"/"… dirToDel…"/"…myFile)
end
end
if(lfs.rmdir(dirToDel)) then
return true
else
return false
end
else
return false
end
end[/lua] [import]uid: 169392 topic_id: 33640 reply_id: 133759[/import]

Thanks. I am almost finish my own code here… it is similar to yours but I am also making it to erase subdirectories as well. I post here later if it works :slight_smile: [import]uid: 181011 topic_id: 33640 reply_id: 133768[/import]