Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powershell脚本删除文件夹正则表达式_Powershell - Fatal编程技术网

powershell脚本删除文件夹正则表达式

powershell脚本删除文件夹正则表达式,powershell,Powershell,我编写了一个Powershell脚本,用于删除名称以0或1开头的给定文件夹中的子文件夹。此脚本似乎仅适用于非空文件夹。我希望它删除内部内容也。是否有任何开关使之成为可能?另外,对于某些文件,我得到一个错误,即当脚本以管理员身份运行时,没有足够的权限 $srcFolder = "C:\Documents and Settings\setup\Desktop\Temp\" $folderList = Get-Childitem $a | Where-Object {$_.Name -match "^

我编写了一个Powershell脚本,用于删除名称以0或1开头的给定文件夹中的子文件夹。此脚本似乎仅适用于非空文件夹。我希望它删除内部内容也。是否有任何开关使之成为可能?另外,对于某些文件,我得到一个错误,即当脚本以管理员身份运行时,没有足够的权限

$srcFolder = "C:\Documents and Settings\setup\Desktop\Temp\"
$folderList = Get-Childitem $a | Where-Object {$_.Name -match "^[01]"}
foreach( $folder in $folderList)
{
    $tempFolder = $srcFolder + $folder;
    Remove-Item $tempFolder
}
有什么想法吗

问候,


Sujeet Kuchibhotla

您可以将其简化很多:

Get-ChildItem $srcFolder | Where {$_.PSIsContainer -and ($_ -match '^[01]')} | 
    Remove-Item -Recurse -WhatIf

您可以将其简化很多:

Get-ChildItem $srcFolder | Where {$_.PSIsContainer -and ($_ -match '^[01]')} | 
    Remove-Item -Recurse -WhatIf