Skip to content

Instantly share code, notes, and snippets.

@jeremycherfas
Last active December 5, 2020 12:20
Show Gist options
  • Save jeremycherfas/c34d9015145ca052a717d10350d528b8 to your computer and use it in GitHub Desktop.
Save jeremycherfas/c34d9015145ca052a717d10350d528b8 to your computer and use it in GitHub Desktop.
increment folder name if folder exists
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