powershell - PowerShell - 将父文件夹名称添加到文件名
问题描述
我有这个文件夹结构
root\1\2\3\1.txt
root\3\2\4\6\1.txt
我想将文本文件重命名为root_1.txt
我尝试过
Get-ChildItem -Recurse *.txt | Rename-Item -NewName %{$_.Parent.Parent.Name + $_.Name}
但这不起作用,因为 Parent 仅适用于目录
解决方案
对于文件项,使用以下Directory
属性:
Get-ChildItem -Recurse *.txt | Rename-Item -NewName {$_.Directory.Parent.Name + $_.Name}
推荐阅读
- javascript - 等待/停止代码执行,直到从服务器获取数据
- python - 在 Python 中为 Postgresql 传递和返回连接和游标
- base64 - Fluentd (td-agent) fluent-plugin-filter-base64-decode v.0.2.0 - 解码不正确
- typescript - 在 Typescript 中从 GatsbyLinkProps 创建组件?
- python - 标准 Scaler 拟合和转换步骤
- python - 如果第一个元素相同,如何将列表的第三个元素相乘?
- windows - Windows 10 中通知状态的注册表值
- angular - Angular 中的 ChangeDetectorRef 实例
- vue.js - Vue.js:从 URL 获取查询字符串参数值
- android - 用户按下电源按钮时如何删除 Firebase 文档