| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | |
| schema | 2.0.0 |
Renames a zip entry (file or directory) within its archive.
Rename-ZipEntry
-ZipEntry <ZipEntryBase>
-NewName <String>
[-PassThru]
[-WhatIf]
[-Confirm]
[<CommonParameters>]The Rename-ZipEntry cmdlet renames a single ZipEntryFile or ZipEntryDirectory object produced by Get-ZipEntry or New-ZipEntry. The operation copies the entry with the new name and deletes the original.
Note
- It's important to note that there is no API in the
System.IO.CompressionNamespace to rename Zip Archive Entries, renaming an entry means creating a copy of the entry with a new name and deleting the old one. This is why the renaming operations can be slow on big Zip Archives. - When renaming an entry that is of type
Directoryyou need to consider that the operation explained in the previous point happens to every entry that is considered a child of the directory you are renaming.
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Type Archive -Include relativePath/to/myEntryToRename.ext |
Rename-ZipEntry -NewName myNewName.extThis example renames a specific file entry inside the zip archive to myNewName.ext.
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Type Archive -Include *.ext |
Rename-ZipEntry -NewName { $_.BaseName + 'myNewName' + $_.Extension }Delay-bind scriptblocks is supported for renaming multiple entries.
Tip
In the context of the delay-bind scriptblock, $_ ($PSItem) represents the current pipeline item, in this case, an instance of PSCompression.ZipEntryFile or PSCompression.ZipEntryDirectory.
PS ..\pwsh> Get-ZipEntry .\PSCompression.zip -Include PSCompression/docs/en-US/*
Directory: /PSCompression/docs/en-US/
Type LastWriteTime CompressedSize Size Name
---- ------------- -------------- ---- ----
Directory 2/22/2024 1:19 PM en-US
Archive 2/22/2024 1:19 PM 2.08 KB 6.98 KB Compress-GzipArchive.md
Archive 2/22/2024 1:19 PM 2.74 KB 8.60 KB Compress-ZipArchive.md
Archive 2/22/2024 1:19 PM 1.08 KB 2.67 KB ConvertFrom-GzipString.md
Archive 2/22/2024 1:19 PM 1.67 KB 4.63 KB ConvertTo-GzipString.md
Archive 2/22/2024 1:19 PM 1.74 KB 6.28 KB Expand-GzipArchive.md
Archive 2/22/2024 1:19 PM 1.23 KB 4.07 KB Expand-ZipEntry.md
Archive 2/22/2024 1:19 PM 1.53 KB 6.38 KB Get-ZipEntry.md
Archive 2/22/2024 1:19 PM 1.67 KB 5.06 KB Get-ZipEntryContent.md
Archive 2/22/2024 1:19 PM 2.20 KB 7.35 KB New-ZipEntry.md
Archive 2/22/2024 1:19 PM 961.00 B 2.62 KB PSCompression.md
Archive 2/22/2024 1:19 PM 1.14 KB 2.95 KB Remove-ZipEntry.md
Archive 2/22/2024 1:19 PM 741.00 B 2.16 KB Rename-ZipEntry.md
Archive 2/22/2024 1:19 PM 1.55 KB 5.35 KB Set-ZipEntryContent.md
PS ..\pwsh> Get-ZipEntry .\PSCompression.zip -Include PSCompression/docs/en-US/ | Rename-ZipEntry -NewName 'en-US123'
PS ..\pwsh> Get-ZipEntry .\PSCompression.zip -Include PSCompression/docs/en-US123/*
Directory: /PSCompression/docs/en-US123/
Type LastWriteTime CompressedSize Size Name
---- ------------- -------------- ---- ----
Directory 2/25/2024 12:41 PM en-US123
Archive 2/25/2024 12:41 PM 2.08 KB 6.98 KB Compress-GzipArchive.md
Archive 2/25/2024 12:41 PM 2.74 KB 8.60 KB Compress-ZipArchive.md
Archive 2/25/2024 12:41 PM 1.08 KB 2.67 KB ConvertFrom-GzipString.md
Archive 2/25/2024 12:41 PM 1.67 KB 4.63 KB ConvertTo-GzipString.md
Archive 2/25/2024 12:41 PM 1.74 KB 6.28 KB Expand-GzipArchive.md
Archive 2/25/2024 12:41 PM 1.23 KB 4.07 KB Expand-ZipEntry.md
Archive 2/25/2024 12:41 PM 1.53 KB 6.38 KB Get-ZipEntry.md
Archive 2/25/2024 12:41 PM 1.67 KB 5.06 KB Get-ZipEntryContent.md
Archive 2/25/2024 12:41 PM 2.20 KB 7.35 KB New-ZipEntry.md
Archive 2/25/2024 12:41 PM 961.00 B 2.62 KB PSCompression.md
Archive 2/25/2024 12:41 PM 1.14 KB 2.95 KB Remove-ZipEntry.md
Archive 2/25/2024 12:41 PM 741.00 B 2.16 KB Rename-ZipEntry.md
Archive 2/25/2024 12:41 PM 1.55 KB 5.35 KB Set-ZipEntryContent.mdThis example renames a directory entry (en-US/) to en-US123/. All child entries are automatically updated to reflect the new parent path.
PS ..pwsh\> Get-ZipEntry .\PSCompression.zip -Include PSCompression/docs/en-US123/ | Rename-ZipEntry -NewName 'Test' -Confirm
Confirm
Are you sure you want to perform this action?
Performing the operation "Rename" on target "PSCompression/docs/en-US123/".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):This example prompts for confirmation before renaming the directory entry. The cmdlet supports ShouldProcess: use -Confirm to prompt or -WhatIf to preview the operation.
Specifies the new name of the zip entry. Enter only a name, not a path and name.
Tip
Delay-bind scriptblock is supported for this parameter. See Example 2.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseOutputs the renamed ZipEntryFile or ZipEntryDirectory object. By default, the cmdlet produces no output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThe zip entries to rename.
Note
- This parameter accepts pipeline input (by value). Binding by property name is also supported.
- Input objects are instances of
ZipEntryFileorZipEntryDirectoryproduced byGet-ZipEntryorNew-ZipEntry.
Type: ZipEntryBase
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe a single ZipEntryFile or ZipEntryDirectory object produced by 'Get-ZipEntry' or New-ZipEntry to this cmdlet.
By default, this cmdlet produces no output.
When the -PassThru switch is used, the cmdlet outputs the renamed entry object.