本帖最后由 ivor 于 2018-12-30 17:13 编辑
- <# :
- @echo off
- rem 增强代码兼容性,代码保存为 ".bat"、".cmd"、".ps1"均可执行
- powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- more +8 "%~f0" >"%~dpn0.ps1"
- powershell -File "%~dpn0.ps1"
- del "%~dpn0.ps1" & pause & exit /b
- #>
-
- $path="C:\Users\mac\Desktop\新建文件夹 - 副本"
-
- $sapi = new-object -com sapi.spvoice
- dir -path "$path" | %{
- if($_.Length -eq $null){
- $parent = -Join($path,"\",$_)
- #<#
- dir -path $parent -recurse | %{
- if($_.Length -ne $null){
- $Newfile = -Join($parent,"\",$_)
- $_.MoveTo($Newfile)
- if(!$?){
- $Newfile = -Join($parent,"\",(Get-Random),"_",$_)
- write-host $_
- $sapi.speak("文件名有重复")
- $_.MoveTo($Newfile)
- }
- }
- }
- ##>
- }
- }
- $sapi.speak("文件复制结束")
- $dirs=$True
- while($dirs){
- $dirs = Get-ChildItem "$path" -recurse | Where {$_.PSIsContainer -and @(Get-ChildItem -LiteralPath:$_.fullname).Count -eq 0}
- $dirs | remove-item -ErrorAction SilentlyContinue
- }
- $sapi.speak("空文件夹已删除")
- $sapi.speak("脚本运行结束")
复制代码 2018年 特别友好版本,语音播报提示
修改10行的path为自己的路径 |