PowerShell 语言 如何重命名文件或目录 Rename Item

PowerShell阿木 发布于 1 天前 4 次阅读


PowerShell 重命名文件或目录:Rename-Item 命令详解

在 PowerShell 中,重命名文件或目录是一项基本且常用的操作。`Rename-Item` 是 PowerShell 提供的一个内置命令,用于重命名文件或目录。本文将深入探讨 `Rename-Item` 命令的用法、参数、注意事项以及一些高级技巧,帮助您更有效地使用这个命令。

`Rename-Item` 命令是 PowerShell 中用于重命名文件或目录的核心工具。它允许用户通过简单的命令行操作来更改文件或目录的名称。本文将围绕 `Rename-Item` 命令展开,详细介绍其使用方法、参数和注意事项。

基础用法

命令格式

```powershell
Rename-Item [-Path] [-NewName ] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-PipelineVariable ] [-UseTransaction] [-ConfirmAction ] [-WhatIfAction ] [-Exclude ] [-Include ] [-Filter ] [-NotMatch ] [-Match ] [-Recurse] [-Depth ] [-Clobber] [-PassThru] [-NoClobber] [-NoRecurse] [-NoNewest] [-Force] [-WhatIf] [-Confirm] [-ErrorAction ] [-ErrorVariable ] [-Out ] [-OutVariable ] [-Pipeline