-
-
Save jeremycherfas/c34d9015145ca052a717d10350d528b8 to your computer and use it in GitHub Desktop.
increment folder name if folder exists
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 create_folder($path, $slug, $counter = 0) | |
{ | |
$folderPath = $path . $slug; | |
if ($counter) { | |
$folderPath .= '-' . $counter; | |
} | |
if (!file_exists($folderPath)) { // Check folder with slug does not exist | |
mkdir($folderPath); //Creates the folder | |
$fn = (($folderPath . '/listen.md')); //Sets the filename | |
return($fn); | |
} | |
create_folder($path, $slug, $counter++); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment