What's new

Tutorial Rename files using Powershell

jaw2lag

Honorary Poster
Sa mga gustong matoto pagrename ng mga files sa loog ng current folder heto ang Powershell command to the rescue.

Code:
powershell -C "gci | % {rni $_.Name ($_.Name -replace 'old-string', 'new-string')}"

Explanation:
--------------------------------------------
Code:
powershell -C "..."
- launches a PowerShell session to run the quoted command.
Code:
-C
- is short for -Command.
Code:
gci
- returns all the files in the current directory. It is an alias for Get-ChildItem.
Code:
| % {...}
- makes a pipeline to process each file. % is an alias for Foreach-Object.
Code:
$_.Name
- is the name of the current file in the pipeline.
Code:
($_.Name -replace 'old-string', 'new-string')
- uses the -replace operator to create the new file name. Each occurrence of the "old-string" is replaced with the "new-string".
Code:
rni
- changes the name of each file. The first parameter (called -Path) identifies the file. The second parameter (called -NewName) specifies the new name. rni is an alias for Rename-Item.
 
misleading yung prefix dapat "Tutorials" maraming salamat pa rin sa share mo sir malaking tulong pa rin to sa mga gusto rin magtago ng bold sa file nila 😆
 

Similar threads

Back
Top