🔒 Closed Rename files using Powershell

Status
Not open for further replies.

jaw2lag

Established
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
  • 612
    Views
  • 3
    Participants
Last reply from:
k4m0t3QT

Trending Topics

Online now

Members online
463
Guests online
1,380
Total visitors
1,843

Forum statistics

Threads
2,287,483
Posts
29,044,851
Members
1,216,560
Latest member
saelxx02
Back
Top