为此,您最好使用 VBScript 或 PowerShell。
VB脚本:
Set fso = CreateObject("Scripting.FileSystemObject")
source = "K:\"
quarantine = "C:\quarantine"
Set re = New RegExp
re.Pattern = "^[^a-z0-9_-]"
re.IgnoreCase = True
For Each fldr In fso.GetFolder(source).SubFolders
If re.Test(fldr.Name) Then
answer = MsgBox("Move " & fldr.Path & "'?", vbYesNo, "Folder Check")
If answer = vbYes Then fldr.Move quarantine & "\"
End If
Next
电源外壳:
$source = "K:\"
$quarantine = "C:\quarantine"
Get-ChildItem $source -Force | ? {
$_.PSIsContainer -and $_.Name -match '^[^a-z0-9_-]'
} | % {
$answer = Read-Host "Move $($_.FullName)? [Y/n]"
if ( $answer.Length -eq 0 -or $answer[0] -eq "y" ) {
$_.MoveTo((Join-Path $quarantine $_.Name))
}
}
这两种解决方案都会检查源文件夹中是否有不以字母数字字符、下划线或连字符开头的文件夹名称,提示用户,然后(在确认后)将该文件夹移动到隔离文件夹。
如果要在 Windows XP 上使用 PowerShell 版本,则必须先安装Windows Management Framework。PowerShell 包含在该软件包中。