Last active
December 19, 2016 03:20
-
-
Save webinista/5f5931643d53cfbf67fb10b7aa4724e2 to your computer and use it in GitHub Desktop.
PHP: Change a file name's extension for every file in an directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function change_extension($filename, $index, $extension) { | |
if (pathinfo($filename, PATHINFO_EXTENSION) == 'md'): | |
$fn = sprintf("%s.%s", pathinfo($filename, PATHINFO_FILENAME), (string)$extension); | |
$success = rename(sprintf('./%s', $filename), $fn); | |
endif; | |
if($success) { | |
printf("Success! %s was renamed to %s\n", $filename, $fn); | |
} | |
} | |
// Sample usage | |
array_walk($files, 'change_extension','markdown'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment