Powershell 如何删除一个目录(包括子目录)中除一个子目录外的所有内容?

Powershell 如何删除一个目录(包括子目录)中除一个子目录外的所有内容?,powershell,Powershell,我正试图使用PowerShell 2为我的angular2应用程序编写一个自动构建和部署脚本,但鉴于我们的ASP.NET Web API如何生活在API/中,我想删除所有旧的angular代码,而不必触碰API 以下是到目前为止我得到的信息: Get-ChildItem -Path $destination -Recurse -exclude somefile.txt | Select -ExpandProperty FullName | Where {$_ -notlike $destina

我正试图使用PowerShell 2为我的angular2应用程序编写一个自动构建和部署脚本,但鉴于我们的ASP.NET Web API如何生活在
API/
中,我想删除所有旧的angular代码,而不必触碰API

以下是到目前为止我得到的信息:

Get-ChildItem -Path  $destination -Recurse -exclude somefile.txt |
Select -ExpandProperty FullName |
Where {$_ -notlike $destination+'\api*'} |
sort length -Descending |
Remove-Item -force -recurse
$destination
是安装应用程序的目录

快速文件夹树,以防我不清楚上面的内容:

$destination
    api\
    app\
    assets\
    vendor\
    index.html
    main.js
    system-config.js

如上所述,我想删除所有内容,但我无权访问PowerShell 2。但是,使用PowerShell 3(及更高版本),您应该能够通过以下方式简化代码:

$path = "C:\test path"
Remove-Item $path -recurse -Exclude "api"
我创建了与您指定的文件夹结构相同的文件夹结构,假设api、应用程序、资产和供应商是子文件夹。我在PowerShell IDE中运行了该脚本,它删除了测试路径下除api文件夹之外的所有内容。我假设PowerShell 2在命令上支持相同的参数