Skip to content

Instantly share code, notes, and snippets.

@dingo-d

dingo-d/rename.php

Last active May 25, 2020
Embed
What would you like to do?
Simple php script to rename folder names to PascalCase from split-name. Doesn't go recursively in subfolders.
#!/usr/bin/env php
<?php
function getDirs( $currentDir ) {
return array_filter( $currentDir, function ( $dir ) {
return is_dir( $dir ) && $dir !== '..' && $dir !== '.';
} );
}
function getFiles( $currentDir ) {
return array_filter( scandir( $currentDir ), function ( $file ) {
return ! is_dir( $file ) && $file !== '..' && $file !== '.';
} );
}
$dirs = getDirs( scandir( __DIR__ ) );
foreach ($dirs as $dir) {
$dirPart = explode('-', $dir);
$newName = '';
foreach ($dirPart as $dirSubname) {
$part = ucfirst($dirSubname);
$newName .= $part;
}
rename(dirname(__FILE__) . '/' . $dir, dirname(__FILE__) . '/' . $newName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment