Search code examples
bashazurepowershellazure-web-app-service

Clearing files on Linux app service, need to exclude a folder


I want to delete the files on my app service prior to deploying ensuring the latest files are present. However, I need to exclude a folder.

I've added -not -path to what was working to attempt to exclude the folder. However, the files in webroot/uploads are still being deleted and not excluded.

$bodyToPOST = @{  
    command = "find . -mindepth 1 -delete -not -path `"/home/site/wwwroot/webroot/uploads/*`""  
    dir = "/home/site/wwwroot"  
}  

# Splat all parameters together in $param  
$param = @{  
    # command REST API url  
    Uri = "https://$WebAppName.scm.omited.appserviceenvironment.net/api/command"  
    Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}  
    Method = "POST"  
    Body = (ConvertTo-Json $bodyToPOST)  
    ContentType = "application/json"  
}  
# Invoke REST call  
Invoke-RestMethod @param 

How can I change this script to exclude the folder webroot/uploads from the delete command?


Solution

  • Someone from the team figured it out, posting for completeness.

    Essentially, -not -path was replaced with !:

    $bodyToPOST = @{  
        command = "find . -mindepth 1 -delete ! ""/home/site/wwwroot/webroot/uploads/*"""  
        dir = "/home/site/wwwroot"  
    }