Removing files

I’m trying to delete an entire folder with the following but get an io exception error is it different for folders and files? What do I have to change?

Var ASfolder As FolderItem = SpecialFolder.Documents.Child("iPuzzleData")

If ASfolder.exists = true then
End if

Does it contain files?

1 Like

This code will not remove a non-empty folder. You must first loop through the folder’s contents and delete each file individually. Then you can do ASfolder.Remove.

After you create ASFolder, pass it as a parameter to a method. I will call this deleteTheFolder.


Var ASfolder as Folderitem=SpecialFolder.Documents.Child(“iPuzzleData”)
if ASfolder.Exists then deleteTheFolder(ASFolder)

Then in your method:

Sub deleteTheFolder(myFolder as FolderItem)

For each thisItem as FolderItem in myFolder.Children

if not thisItem.IsFolder then
'We found a subfolder, so we’ll call recursively
end if

'The folder is now empty

HTH :slight_smile:

PS: You may do this a little more simply if you don’t expect to find subfolders. Oh, and Happy New Year :smiley:

Happy New Year Jerry from Oz and thanks :beer:

1 Like