[英]Powershell how to move files with specific file name length
I am trying to move files with file name length is 14 characters to a folder.我正在尝试将文件名长度为 14 个字符的文件移动到文件夹中。
For example,file name CWCA1175034366.pdf will be move to specific folder and file name 12345.pdf will not be moved.例如,文件名 CWCA1175034366.pdf 将移动到特定文件夹,文件名 12345.pdf 将不会移动。
Here is what I tried but failed.这是我尝试但失败的方法。
foreach ($file in (Get-ChildItem \\i28699\TW.ASML_GBW\EV\AWB\*.pdf -Recurse)) {
if ($file.Name.length eq 14) {
Move-Item $file \\i28699\TW.ASML_GBW\EV\AWB\Renamed
}
}
Can someone help me with that?Thanks.有人可以帮我吗?谢谢。
Code LGTM but you're missing the '-' from '-eq' to tell it to use that comparison operator.代码 LGTM 但您缺少“-eq”中的“-”来告诉它使用该比较运算符。
From your example I think you mean the length of the file's BaseName
, so 14 characters without counting the extension.从你的例子来看,我认为你的意思是文件的
BaseName
的长度,所以 14 个字符不计算扩展名。
Try尝试
Get-ChildItem -Path '\\i28699\TW.ASML_GBW\EV\AWB\*.pdf' -File -Recurse |
Where-Object { $_.BaseName.Length -eq 14 } |
Move-Item -Destination '\\i28699\TW.ASML_GBW\EV\AWB\Renamed'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.