本帖最后由 ivor 于 2017-12-17 12:53 编辑
回复 1# wpy4206
powershell 脚本:
功能:以当前文件为基准,只移动深度三层目录下所有JPG图片至二层目录,然后删除空目录
- 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
- }
- }
- }
- }
- }
- }
复制代码 |