[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 ivor 于 2018-12-30 17:13 编辑
  1. <# :
  2. @echo off
  3. rem 增强代码兼容性,代码保存为 ".bat"、".cmd"、".ps1"均可执行
  4. powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  5. more +8 "%~f0" >"%~dpn0.ps1"
  6. powershell -File "%~dpn0.ps1"
  7. del "%~dpn0.ps1" & pause & exit /b
  8. #>
  9. $path="C:\Users\mac\Desktop\新建文件夹 - 副本"
  10. $sapi = new-object -com sapi.spvoice
  11. dir -path "$path" | %{
  12.     if($_.Length -eq $null){
  13.         $parent = -Join($path,"\",$_)
  14.         #<#
  15.         dir -path $parent -recurse | %{
  16.         if($_.Length -ne $null){
  17.             $Newfile = -Join($parent,"\",$_)
  18.             $_.MoveTo($Newfile)
  19.             if(!$?){
  20.                 $Newfile = -Join($parent,"\",(Get-Random),"_",$_)
  21.                 write-host $_
  22.                 $sapi.speak("文件名有重复")
  23.                 $_.MoveTo($Newfile)
  24.                 }
  25.             }
  26.         }
  27.         ##>
  28.     }
  29. }
  30. $sapi.speak("文件复制结束")
  31. $dirs=$True
  32. while($dirs){
  33.         $dirs = Get-ChildItem "$path" -recurse | Where {$_.PSIsContainer -and @(Get-ChildItem -LiteralPath:$_.fullname).Count -eq 0}
  34.         $dirs | remove-item -ErrorAction SilentlyContinue
  35. }
  36. $sapi.speak("空文件夹已删除")
  37. $sapi.speak("脚本运行结束")
复制代码
2018年 特别友好版本,语音播报提示
修改10行的path为自己的路径
1

评分人数

    • yhcfsr: 这个方法来兼容PS的确不错技术 + 1

TOP

7楼代码已更新
1

评分人数

TOP

返回列表