powershell Rename-Item fail to rename

前端 未结 1 1569
日久生厌
日久生厌 2020-12-16 02:24

My powershell script:

$dst = \'C:\\Temp\'

#Get all folders in $dst
$folders = Get-ChildItem $dst | ?{ $_.         


        
相关标签:
1条回答
  • 2020-12-16 02:58

    If you are running PS 3+ add -LiteralPath switch to your rename:

    Rename-Item -LiteralPath $folder.FullName $newname
    

    otherwise use Move-Item

    Move-Item -LiteralPath $folder.FullName $newname
    

    Powershell doesn't like square brackets in filenames, more in the following post:

    This became an issue with V2 when they added the square brackets to the wildcard character set to support "blobbing".

    From get-help about_wildcards:

    Windows PowerShell supports the following wildcard characters.

    Wildcard Description Example Match No match


    • Matches zero or a* A, ag, Apple banana more characters

      ? Matches exactly ?n an, in, on ran one character in the specified position

      [ ] Matches a range [a-l]ook book, cook, look took of characters

      [ ] Matches specified [bc]ook book, cook hook characters

    [ and ] are special characters.

    0 讨论(0)
提交回复
热议问题