1

We want to copy or delete the files from the root folder of Azure app service(web app).

We have multiple web application hosted in azure, we need to copy/download and delete the files from the root folder of all the web application using another web application.

Note: we are creating new web app which will access the other web application's root folder and copy/delete the files.

d:\\home\site\wwwroot\LogFiles
Harshitha
  • 3,784
  • 2
  • 4
  • 9
Meghraj
  • 11
  • 3

1 Answers1

1

delete the files from the root folder of Azure app service(web app)

For the Azure Windows App Service:

  • If the Web App is deployed to Azure Windows App Service, you will find an option to delete the files in KUDU Console. Path to KUDU - https://YourAppName.scm.azurewebsites.net/DebugConsole

OR

Navigate to your deployed App => Advanced Tools => Go

enter image description here

Debug console => cmd => site => wwwroot , you will find all the deployed files/folders. Option to edit/delete/download can be seen.

enter image description here

For the Azure Linux App Service:

Thanks @Dillion Megida for the commands.

In the Azure Linux App Service, navigate to DebugConsole =>Bash => site => wwwroot folder.

with ls, you can see the existing files and folders.

  • Navigate to the folder where you want to delete the files.

run the below command to delete a single file.

rm filename

Ex: rm appsettings.json

enter image description here

To delete folder/directory, use the below command.

rm -r FolderName

enter image description here

Update:

Thanks @Niels Swimberghe for the PowerShell Script.

Create a PowerShell script with the LogFiles path and save as .ps1 extension.

$LogFolder = "C:\home\LogFiles";
$DaysToKeepLogsAround = 30;
Get-ChildItem -Path $LogFolder -Recurse ->File | Where LastWriteTime  -lt  (Get-Date).AddDays(-$DaysToKeepLogsAround) | Remove-Item -Force
  • In the Deployed App service => Web Jobs => Create a Web Job .

enter image description here

  • Select the WebJob and click on run to test the script.
  • You can see the files before 30 days got deleted.

enter image description here

  • Check the WebJob Status under Logs.

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • He does not want to delete files manually or by going to the KUDO, etc. What he wants is for another app (probably a function app or web API) to connect to these paths (as he has multiple sites hosted) and access the files and delete them from a single place via code. – Amnesh Goel Jan 03 '23 at 11:07
  • 1
    Ok..Will work on it and let you know. – Harshitha Jan 03 '23 at 11:09
  • @Meghraj Belikatti - Do you want to delete all the `LogFiles`? – Harshitha Jan 03 '23 at 12:08
  • No @Harshitha, we want to delete the files which are created one month before. – Meghraj Jan 03 '23 at 12:13
  • File means , are you looking for any particular folder ? or the files under `LogFiles` ? – Harshitha Jan 03 '23 at 12:14
  • 1
    Yes, we want to delete/copy/download the files under the LogFiles folder. – Meghraj Jan 03 '23 at 12:18
  • @Meghraj Belikatti - Please check the `Update` section in the posted answer. – Harshitha Jan 03 '23 at 13:48
  • @Harshitha - As I mentioned, we want to do this functionality through Web App or Function App. We have already one pipeline in place, but we want to do this through the Web App or Function app. – Meghraj Jan 04 '23 at 05:24
  • I haven't found any code related to deleting the Azure logs from c# code. AFAIK, `Powershell` Script with `Azure Web Jobs` is the easy option to delete the Azure log files. – Harshitha Jan 17 '23 at 09:22