Get-ChildItem找不到文件

时间:2018-02-04 20:53:10

标签: powershell

目录中有.mp4文件。使用通配符列出文件项。但是,指定完整文件名不会导致列表。我尝试用反引号字符转义方括号,但仍然没有列表。如何说服Get-ChildItem识别此文件?

C:>Get-ChildItem 'C:\src\t\t\Some*'

    Directory: C:\src\t\t

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2018-02-04     14:25              6 Some other Artist - Song Tittle [HD]-ZN9cJvl-P4c.mp4


PS 14:48  C:\src\t\t
C:>Get-ChildItem 'C:\src\t\t\Some other Artist - Song Tittle [HD]-ZN9cJvl-P4c.mp4'

C:>Get-ChildItem 'C:\src\t\t\Some other Artist - Song Tittle [HD]-ZN9cJvl-P4c.mp4' | Measure-Object

Count    : 0
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

使用-LiteralPath的问题在于它在使用通配符时不起作用,因为它是文字的。这让我觉得我必须做Get-ChildItem -Filter '*.mp4',然后在ForEach-Object做另一个Get-ChildItem -LiteralPath $_.FullName。这需要吗?有没有更好的办法?

以下代码使用-LiteralPath,但仍然失败。

Get-ChildItem -File -Filter '*.mp4' |
    ForEach-Object {
        Get-ChildItem -LiteralPath $_.FullName |
            ForEach-Object {
                Rename-Item `
                    -Path $_.FullName `
                    -NewName $($_.Name -replace '(.*[\)\]])-.*(\.mp4) ','$1$2') `
                    -WhatIf
            }
    }

错误讯息。

Rename-Item : Cannot rename because item at 'Some other Artist - Song Tittle [HD]-ZN9cJvl-P4c.mp4' does not exist.

0 个答案:

没有答案