将文件批量重命名为祖父母目录名称

目录结构如下所示:

D:\ folder0 \ subdir1 \ scan0001.tif D:\ folder0 \ subdir2 \ scan0001.tif D:\ folder0 \ subdir3 \ scan0001.tif

D:\ folder0 \ subdir1 \ RAW \ raw0001.tif D:\ folder0 \ subdir2 \ RAW \ raw0001.tif D:\ folder0 \ subdir3 \ RAW \ raw0001.tif

当前RAW目录中的文件命名为 “ raw0001.tif” “ raw0002.tif” “ raw0003.tif”

我想将它们重命名为 “ subdir1原始01.tif” “ subdir1原始的02.tif” “ subdir1原始03.tif”

I found how to rename files in subdir# by executing
ls *tif |
Foreach {$i=1} {Rename-Item $_ -NewName ("$($_.directory.name) scan {0:0#}.tif" -f
$i++)}

但是我陷入了如何修改上述命令以查看祖父母目录(subdir1)的问题。

评论