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

powershell
递归处理所有子目录
在所有级间都添加了 "-"
武器-现代-01-01
稍微有点不符合
  1. function f-1()
  2. {
  3.     push-location $args[0]
  4.     $p = (get-item .).name
  5.     Get-ChildItem -Directory | foreach-object {
  6.         Rename-Item $_ -NewName ($p + "-" + $_.name)
  7.     }
  8.     Get-ChildItem -Directory | foreach-object {
  9.         f-1 $_.name
  10.     }
  11.     pop-location
  12. }
  13. f-1 "C:\Users\admin\Desktop\aaa"
复制代码

TOP

本帖最后由 newswan 于 2021-8-1 22:58 编辑

回复 3# mypcl01


  随便在哪里,用你目标目录代替 aaa 哪里,那是测试目录

TOP

回复 6# mypcl01

先看看这个
http://www.bathome.net/thread-59270-1-1.html
  1. function f-1()
  2. {
  3.     push-location $args[0]
  4.     $p = (get-item .).name
  5.     Get-ChildItem -Directory | foreach-object {
  6.         if ( -not ($_.basename).contains("-") )
  7.         {
  8.             Rename-Item $_ -NewName ($p + "-" + $_.name)
  9.         }
  10.     }
  11.     Get-ChildItem -Directory | foreach-object {
  12.         f-1 $_.name
  13.     }
  14.     pop-location
  15. }
  16. f-1 "."
复制代码
"." 表示本目录
添加了一个判断,已经处理过的不再处理,不需要的话,删除 6 7 9 行

TOP

本帖最后由 newswan 于 2021-8-6 12:28 编辑

powershell
  1. function f-1()
  2. {
  3.     push-location $args[0]
  4.     $p = (get-item .).name
  5.     Get-ChildItem -Directory | foreach-object {
  6.         Rename-Item $_ -NewName ($p + "-" + $_.name)
  7.     }
  8.     Get-ChildItem -Directory | foreach-object {
  9.         f-1 $_.name
  10.     }
  11.     pop-location
  12. }
  13. function fl-1()
  14. {
  15.     push-location $args[0]
  16.     $p = (get-item .).name
  17.     $count = 0
  18.     Get-ChildItem -File "*.txt" | foreach-object {
  19.         $count += 1
  20.         Rename-Item $_ -NewName ($p + "-" + $count.ToString().PadLeft(2,"0") + $_.Extension)
  21.     }
  22.     Get-ChildItem -Directory | foreach-object {
  23.         Rename-Item $_ -NewName ($p + $_.name)
  24.     }
  25.     Get-ChildItem -Directory | foreach-object {
  26.         fl-2 $_.name
  27.     }
  28.     pop-location
  29. }
  30. function fl-2()
  31. {
  32.     push-location $args[0]
  33.     $p = (get-item .).name
  34.     $count = 0
  35.     Get-ChildItem -Directory | foreach-object {
  36.         $count += 1
  37.         Rename-Item $_ -NewName ($p + $count.ToString().PadLeft(2,"0"))
  38.     }
  39.     Get-ChildItem -Directory | foreach-object {
  40.         fl-3 $_.name
  41.     }
  42.     pop-location
  43. }
  44. function fl-3()
  45. {
  46.     push-location $args[0]
  47.     $p = (get-item .).name
  48.     $count = 0
  49.     Get-ChildItem -File "*.txt" | foreach-object {
  50.         $count += 1
  51.         Rename-Item $_ -NewName ($p + "-" + $count.ToString().PadLeft(2,"0") + $_.Extension)
  52.     }
  53.     pop-location
  54. }
  55. fl-1 "."
复制代码

TOP

本帖最后由 newswan 于 2021-8-6 12:21 编辑

回复 10# mypcl01


你可以发 目录树
  1. C:\Users\admin\Desktop\aaa>tree /f
  2. Folder PATH listing
  3. Volume serial number is DC2F-31AE
  4. C:.
  5. │   a.ps1
  6. │   a.txt
  7. │   a2.txt
  8. │   a6.txt
  9. │   b.txt
  10. │   b1.txt
  11. │   b2.txt
  12. ├───1
  13. │   ├───11
  14. │   │       a11
  15. │   │       a22
  16. │   │
  17. │   └───22
  18. │           a11
  19. │           a22
  20. └───2
  21.     ├───11
  22.     │       a11
  23.     │       a22
  24.     │
  25.     └───22
  26.             a11
  27.             a22
复制代码

TOP

需求翻译:

目录树有三级
一级\二级\三级

目录更名
一级\一级二级\一级二级num

文件更名
一级目录  一级-num
三级目录  一级二级-num
1

评分人数

TOP

返回列表