首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Powershell -include字符串中包含文件夹

如何在Powershell -include字符串中包含文件夹
EN

Stack Overflow用户
提问于 2020-09-02 03:22:37
回答 2查看 42关注 0票数 1

我正在进行一些批量文件名更新,并且在包含文件夹时遇到问题。我目前将其设置为仅针对特定的文件类型,但我也希望包含文件夹。由于文件夹没有扩展名,我不确定如何在"-include“字符串中指定文件夹。任何帮助都将不胜感激。

这是我目前正在使用的,但当我想要包含文件夹时,它会忽略这些文件夹。

代码语言:javascript
运行
复制
Get-ChildItem k:/toolbox/powershell -Include *.gif, *.jpg, *.png, *.xls, 
*.xlsx, *.ppt, *.pptx, *.doc, *.docx, *.pdf -recurse | where {$_.name -match 
"_"} | foreach {
  $New=$_.name.Replace("_","-")
  Rename-Item -path $_.Fullname -newname $New -passthru
}
EN

回答 2

Stack Overflow用户

发布于 2020-09-02 03:46:56

代码语言:javascript
运行
复制
(Get-Item '~\Desktop\*') | foreach { $FolderName = $_.name.Replace("_","-"); Rename-Item -path $_.fullname -newname $FolderName -passthru }
票数 0
EN

Stack Overflow用户

发布于 2020-09-03 19:19:12

我只想加上第二句话:

代码语言:javascript
运行
复制
Get-ChildItem "k:/toolbox/powershell" -Recurse |where mode -eq d----- | where {$_.name -match "_"} | foreach {$New=$_.name.Replace("_","-")
Rename-Item -path $_.Fullname -newname $New -passthru } 

如果您运行Get-ChildItem "k:/toolbox/powershell",您将收到目录的“模式”为“d-”的项目列表,因此您可以对目录使用该筛选条件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63694136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档