简体   繁体   English

Powershell 如何移动特定文件名长度的文件

[英]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.

相关问题 如何使用 PowerShell 搜索特定文件名然后将该文件之后的所有文件移动到另一个文件夹 - How to search for a specific file name then move all files after that file to another folder using PowerShell powershell根据文件名的一部分移动文件 - powershell to move files based on part of file name 如何只在powershell中移动特定的文件类型 - how to only move specific file types in powershell Powershell将文件移动到特定文件夹 - Powershell Move Files to a specific folder Powershell:提取文件名的一部分以创建文件夹并将文件移动到文件夹中 - Powershell: Extracting parts of file name to create folders and move files into the folder 根据文件名时间戳Powershell将文件移动到年/月文件夹 - Move files into year/month folders based on file name timestamp powershell Powershell根据文件名的初始部分移动Excel文件 - Powershell to move Excel files based on Initial part of the file name 如何使用Powershell根据文件名将文件移动到“文件夹和子文件夹”? - How to move files to Folder and Sub folder based on file name using Powershell? 如何创建 powershell 脚本以将特定文件移动到其他位置? - How to create a powershell script to move specific files to a different location? 如何仅使用Powershell从特定文件夹移动文件 - How to move files from specific folders only using powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM