Forked from jeremycherfas/incrementFolderName.txt
Last active
March 15, 2019 14:19
-
-
Save sknebel/c02a3f83c8273743e86b0da1723574b6 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; | |
} | |
return create_folder($path, $slug, $counter++); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment