You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example shows that you cannot use `Rename-Item` to both rename and move an item.
52
-
Specifically, you cannot supply a path for the value of the **NewName** parameter, unless the path is identical to the path specified in the **Path** parameter.
53
-
Otherwise, only a new name is permitted.
51
+
You can't use `Rename-Item` to both rename and move an item. Specifically, you can't supply a path
52
+
for the value of the **NewName** parameter, unless the path is identical to the path specified in
53
+
the **Path** parameter. Otherwise, only a new name is permitted.
54
54
55
-
This command attempts to rename the "project.txt" file in the current directory to "old-project.txt" in the "D:\Archive" directory. The result is the error shown in the output.
55
+
This example attempts to rename the `project.txt` file in the current directory to `old-project.txt`
56
+
in the `D:\Archive` directory. The result is the error shown in the output.
This example shows how to use the **Replace** operator to rename multiple files, even though the **NewName** parameter does not accept wildcard characters.
81
+
This example renames all the `*.txt`files in the current directory to `*.log`.
78
82
79
-
This command renames all of the ".txt" files in the current directory to ".log".
80
-
81
-
The command uses the `Get-ChildItem` cmdlet to get all of the files in the current folder that have a .txt file name extension.
82
-
Then, it uses the pipeline operator (`|`) to send those files to `Rename-Item`.
83
+
```powershell
84
+
Get-ChildItem *.txt
85
+
```
83
86
84
-
The value of **NewName** is a script block that runs before the value is submitted to the **NewName** parameter.
87
+
```Output
88
+
Directory: C:\temp\files
85
89
86
-
In the script block, the `$_` automatic variable represents each file object as it comes to the command through the pipeline.
87
-
The command uses the dot format ('.') to get the **Name** property of each file object.
88
-
The **Replace** operator replaces the ".txt" file name extension of each file with ".log".
90
+
Mode LastWriteTime Length Name
91
+
---- ------------- ------ ----
92
+
-a---- 10/3/2019 7:47 AM 2918 Friday.TXT
93
+
-a---- 10/3/2019 7:46 AM 2918 Monday.Txt
94
+
-a---- 10/3/2019 7:47 AM 2918 Wednesday.txt
95
+
```
89
96
90
-
Because the **Replace** operator works with regular expressions, the dot in front of "txt" is interpreted to match any character.
91
-
To make sure that it matches only a dot ('.'), it is escaped with a backslash character (\\).
92
-
The backslash character is not required in ".log" because it is a string, not a regular expression.
This cmdlet supports the common parameters: `-Debug`, `-ErrorAction`, `-ErrorVariable`, `-InformationAction`, `-InformationVariable`, `-OutVariable`, `-OutBuffer`, `-PipelineVariable`, `-Verbose`, `-WarningAction`, and `-WarningVariable`. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
290
+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md).
276
293
277
294
## INPUTS
278
295
@@ -284,12 +301,13 @@ You can pipe a string that contains a path to this cmdlet.
284
301
285
302
### None or an object that represents the renamed item.
286
303
287
-
This cmdlet generates an object that represents the renamed item, if you specify the *PassThru* parameter.
288
-
Otherwise, this cmdlet does not generate any output.
304
+
This cmdlet generates an object that represents the renamed item, if you specify the **PassThru**
305
+
parameter. Otherwise, this cmdlet does not generate any output.
289
306
290
307
## NOTES
291
308
292
-
`Rename-Item`is designed to work with the data exposed by any provider. To list the providers available in your session, type `Get-PsProvider`. For more information, see [about_Providers](../Microsoft.PowerShell.Core/About/about_Providers.md).
309
+
`Rename-Item`is designed to work with the data exposed by any provider. To list the providers
310
+
available in your session, type `Get-PsProvider`. For more information, see [about_Providers](../Microsoft.PowerShell.Core/About/about_Providers.md).
0 commit comments