我是一名有帮助的助手,以下是您需要翻译的内容:
我需要删除所有文件类型,除了网站bin文件夹中的pdb文件和网站文件夹中的ASAX文件。现在使用Get-ChildItem进行递归搜索,但是它忽略了这些文件。是否由于递归结构中的项目深度导致的?或者是其他原因?如何修复它,以便根据规定删除所有文件。
编辑:我尝试添加-force参数,但没有改变任何内容。
答案:以下内容可以解决问题。
我正在编写一个PowerShell脚本,用于删除文件夹中的某些文件,并将其余文件移动到预定义的子文件夹中。
我的目录结构如下:
Main
(Contains a bunch of pdb and dll files)
-- _publish
--Website
(Contains a web.config, two other .config files and a global.asax file)
-- bin
(Contains a pdb and dll file)
-- JS
-- Pages
-- Resources
在开始移动文件之前,我希望从整个文件结构中删除所有的pdb、config和asax文件。我使用以下命令:
$pdbfiles = Get-ChildItem "$executingScriptDirectory\*.pdb" -recurse
foreach ($file in $pdbfiles) {
Remove-Item $file
}
我需要删除所有文件类型,除了网站bin文件夹中的pdb文件和网站文件夹中的ASAX文件。现在使用Get-ChildItem进行递归搜索,但是它忽略了这些文件。是否由于递归结构中的项目深度导致的?或者是其他原因?如何修复它,以便根据规定删除所有文件。
编辑:我尝试添加-force参数,但没有改变任何内容。
答案:以下内容可以解决问题。
$include = @("*.asax","*.pdb","*.config")
$removefiles = Get-ChildItem "$executingScriptDirectory\*" -recurse -force -include $include
foreach ($file in $removefiles) {
if ($file.Name -ne "Web.config") {
Remove-Item $file
}
}
Get-ChildItem -force
吗? - CB.$PSVersionTable
变量来检查。 - JamesQMurphy