access/copy/delete the files of root folder from the azure app service(web app) using another web application

1.1k Views Asked by At

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
1

There are 1 best solutions below

9
On

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