[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 ivor 于 2019-1-10 14:14 编辑

  1. Function GenerateNewName{
  2.     Param( [System.IO.FileInfo]$FilePath )
  3.     $int = 0
  4.     while(test-Path $FilePath.FullName){
  5.         $int ++
  6.         $FilePath = "{0}\{1}{2:D3}{3}" -f ($FilePath.DirectoryName,(([char[]]$FilePath.BaseName)[0..39] -join ""),$int,$FilePath.Extension)
  7.     }
  8.     Return $FilePath.FullName
  9. }
  10. dir C:\ceshi -File -Recurse | %{if (($_.BaseName).Length -gt 40){Move-Item $_.FullName (GenerateNewName($_)) -Verbose}}
复制代码
1

评分人数

TOP

本帖最后由 ivor 于 2019-1-10 15:37 编辑

  1. Function GenerateNewName{
  2.     Param( [System.IO.FileInfo]$FilePath )
  3.     $int = 0
  4.     while(test-Path $FilePath.FullName){
  5.         $int ++
  6.         $FilePath = "{0}\{1}{2:D3}{3}" -f ($FilePath.DirectoryName,(([char[]]$FilePath.BaseName)[0..39] -join ""),$int,$FilePath.Extension)
  7.     }
  8.     Return $FilePath.FullName
  9. }
  10. dir C:\ceshi -Recurse | %{if ($_ -is [System.IO.FileInfo] -and ($_.BaseName).Length -gt 40){Move-Item $_.FullName (GenerateNewName($_)) -Verbose}}
复制代码
1

评分人数

TOP

  1. Function GenerateNewName{
  2.     Param( [System.IO.FileInfo]$FilePath )
  3.     $int = 0
  4.     if($pool.ContainsKey($FilePath.BaseName)){
  5.         $FilePath = "{0}\{1}{2}" -f ($FilePath.DirectoryName,$pool[$FilePath.BaseName],$FilePath.Extension)
  6.     }
  7.     while(test-Path $FilePath.FullName){
  8.         $int ++
  9.         $FilePath = "{0}\{1}{2:D3}{3}" -f ($FilePath.DirectoryName,(([char[]]$FilePath.BaseName)[0..39] -join ""),$int,$FilePath.Extension)
  10.     }
  11.     $pool[$FilePath.BaseName]=$FilePath.BaseName
  12.    
  13.     Return $FilePath.FullName
  14. }
  15. $pool = @{}
  16. dir C:\ceshi -Recurse | %{if ($_ -is [System.IO.FileInfo] -and ($_.BaseName).Length -gt 40){
  17. Move-Item $_.FullName (GenerateNewName($_)) -Verbose
  18. }}
复制代码
1

评分人数

    • happyaya: 感谢给帖子标题标注[已解决]字样技术 + 1

TOP

返回列表