本帖最后由 zaqmlp 于 2022-6-24 11:45 编辑
- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $level=2;
-
- $folders=@(
- ".\111\222",
- ".\111\333"
- );
-
- $reg='(\\[^\\]+){'+$level.ToString()+'}$';
- for($i=0;$i -lt $folders.length;$i++){
- if(test-path -literal $folders[$i]){
- $folders1=@(dir -literal $folders[$i] -recurse|?{$_ -is [System.IO.DirectoryInfo]});
- for($j=0;$j -lt $folders1.length;$j++){
- $folders2=@(dir -literal $folders1[$j].FullName|?{$_ -is [System.IO.DirectoryInfo]});
- if($folders2.length -eq 0){
- $fd=$folders1[$j].FullName -replace $reg,'';
- if($fd -ne $folders1[$j].FullName){
- if(test-path -literal $fd){
- write-host $folders1[$j].FullName -NoNewline;
- write-host ' --> ' -NoNewline;
- write-host $fd -ForegroundColor yellow;
- remove-item -literal $fd -recurse -force -ErrorAction SilentlyContinue;
- }
- }
- }
- }
- }else{write-host ('"'+$folders[$i]+'" not found');}
- }
复制代码
|