Unable to delete a folder through WINAPI::Deletefile()

Hi Pioneers,

I am unable to delete a FOLDER through WINAPI::DeleteFile() command. I am ABLE to delete ZIP and individual files using the command, but for the folder, I am unable to delete it.

Is there any command to delete the directory ?

DeleteFile() is indeed for deleting a file. If you want to delete a directory with all its content, use System.IO.Directory::Delete() with the second argument (“recursive”) set to true.
Don’t forget to handle CLR exceptions in some way.

Yes I am able to get the file deleted. Please let me know , if this can delete in Non-Batch mode ?

Of course. The .NET library doesn’t care about whether you’re calling it from an AX batch or anything else.


What is second parameter “recursive” meant ?

You don’t need others to answer it for you; you can easily do it by yourself. You know both the class (System.IO.Directory) and the method (Delete), so you can put them to a search engine and find the documentation. Here it is: Directory.Delete Method (String, Boolean).

There you can read documentation for recursive; I’ll leave it for you.

If you wonder what happens if recursive is false, look at exceptions. You’ll learn that IOException is thrown if recursive is false and path is not an empty directory.