Skip to content

Instantly share code, notes, and snippets.

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