Deleting files from an azure app service web app

As a user, I would like to be able to delete certain files and directories from my azure app service web app before deploying my application.

I’ve tried adding a custom script, that runs on the deployment target, but it was unable to find the C:\home\site\wwwroot directory.

I keep getting
ObjectNotFound: Cannot find path ‘C:\home\site’ because it does not exist.

I’ve tried the azure script, normal script, and the pre-deployment custom script on the Deploy an Azure Web App step but I’m getting the same error.

What’s the best way to do this?

Is this answer still the only way we can delete files/folders from an azure app service?

Hi ,
Thanks for reaching out!

With the way that Azure apps work there are restrictions on how you can achieve this. However using a Powershell script and FTP module is probably the best option in your case.

There is a good example on how to do this in this StackOverflow answer:

That answer has two methods but arguably the FTP module is the cleaner of the two and controlled within Octopus with your project variables available to you as a result.

Let me know if this works out for you,

Kind Regards,
Paraic

Ah thanks for that idea. I didn’t consider using a custom webjob to clean up the directories.

I’ll have a look at that as at the moment we’re using the KUDU API and passing a command to delete the files. This feel a bit dangerous though so we might consider the webjob option.