🔒 Closed Rename files using Powershell

Status
Not open for further replies.

jaw2lag

Eternal 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 😆
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 608
    Views
  • 3
    Participants
Last reply from:
k4m0t3QT

Trending Topics

Online now

Members online
950
Guests online
1,125
Total visitors
2,075

Forum statistics

Threads
2,273,859
Posts
28,952,103
Members
1,234,979
Latest member
alealahya
Back
Top