开发者

powershell script delete folders regular expression

I've written a Powershell script to delete subfolders within a given folder whose name starts with either 0 or 1. This 开发者_StackOverflowscript seems to work only for non-empty folders. I want it to delete the inner contents too. Is there any switch that makes it possible? Also, for some files, I get an error about not having enough permissions whereas the script runs as an administrator.

$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
}

Any ideas?

Regards,

Sujeet Kuchibhotla


You can simplify this quite a bit:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜