本帖最后由 ivor 于 2017-12-17 16:53 编辑
回复 12# wpy4206
好吧,现在可以存为bat文件运行此代码了。- <# :
- @echo off
- rem 增强代码兼容性,代码保存为 ".bat"、".cmd"、".ps1"均可执行
- powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- more +8 %~f0 > %~dpn0.ps1
- powershell %~dpn0.ps1
- del %~dpn0.ps1&pause&exit /b
- #>
- foreach ($dir in @(dir .\*\*\*))
- {
- $count = 0
- foreach ($file in @(dir $dir))
- {
- if ($file.Extension -eq ".jpg"){
- if (! $file.PSIsContainer){
- if ($dir.Parent){
- $count += 1
- $new_file = -Join($dir.name,"(",$count,")",$file.Extension)
- $dest = -Join(".\",$dir.Parent.Parent,"\",$dir.Parent,"\",$new_file)
- $file.Moveto($dest)
- write-host 正在移动:$file
- if( (Get-ChildItem $dir | Measure-Object).Count -eq 0) {
- rd $dir
- write-host 删除目录:$dir
- }
- }
- }
- }
- }
- }
复制代码
|