简体   繁体   English

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

[英]How to include folders in Powershell -include string

I am doing some batch file name updates and am having trouble including folders.我正在做一些批处理文件名更新,但在包含文件夹时遇到问题。 I have it currently set to target only specific file types, but I also want to include folders.我目前将其设置为仅针对特定文件类型,但我也想包括文件夹。 Since folders don't have an extension I am unsure how to specify folders in the "-include" string.由于文件夹没有扩展名,我不确定如何在“-include”字符串中指定文件夹。 Any help would be greatly appreciated.任何帮助将不胜感激。

Here is what I am currently working with, but it ignores folders when I would like them included.这是我目前正在使用的内容,但是当我希望包含文件夹时它会忽略它们。

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
}
(Get-Item '~\Desktop\*') | foreach { $FolderName = $_.name.Replace("_","-"); Rename-Item -path $_.fullname -newname $FolderName -passthru }

I would just add 2nd statement:我只想添加第二个声明:

Get-ChildItem "k:/toolbox/powershell" -Recurse |where mode -eq d----- | where {$_.name -match "_"} | foreach {$New=$_.name.Replace("_","-")
Rename-Item -path $_.Fullname -newname $New -passthru } 

If you run Get-ChildItem "k:/toolbox/powershell" you will receive a list of items where the "Mode" is "d-----" for directories, hence you can use that filter criteria for directories如果您运行Get-ChildItem "k:/toolbox/powershell"您将收到一个项目列表,其中目录的“模式”为“d-----”,因此您可以对目录使用该过滤条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM