in PHP

Rename multiple file to capitalize first letter only in git repository using Powershell

I’m mostly using Codeigniter while developing PHP based apps.  The most annoying thing, I always got a gig to extend or (re)developing an apps that its last updated years ago. Mostly based of Codeigniter 2. For some reason, I always upgrade it to Codeigniter 3, and that would be another pain in the ass.

Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers and models) must be named in a Ucfirst-like manner or in other words – they must start with a capital letter.

Yes, renaming all files is pain in the ass. More over on the OS that not-case-sensitive like Windows. So, manual renaming or using 3rd party apps will be meaningless, GIT won’t consider any modification.

Using git mv is the solution. But writing git mv for all files in CLI/bash/powershell is double pain in the ass.  I searched bash command (linux related) and it added another pain, lol.  Luckily I found Powershell which code like VB (and I known better than other CLI) at stackoverflow. With modification for my need here the code:

Get-ChildItem -Filter "*.php" -recurse -File | foreach { git mv $_.FullName ($_.FullName.substring(0, $_.FullName.length - $_.Name.length)+$_.Name.substring(0,1).toupper()+$_.Name.substring(1).tolower()) }

Note:
-Filter “*.php” for search PHP files only.
-recurse to search recursively.
$_.FullName is fullpath of file, that’s why I used substring to make sure, we renaming, the first letter and the filename only.

Write a Comment

Comment