$dirName = '<directory>';
$fileName = 'file';
$dir = scandir($dirName);
if (!in_array($fileName, $dir)) {
touch($dirName.'/'.$fileName);
}
else {
$maxIndex = 1;
foreach ($dir as $fName) {
if ($fName == '.' || $fName == '..') continue;
if (preg_match('/\((\d+)\)(\w+)/', $fName, $matches) == 1) {
$maxIndex = max($maxIndex, $matches[1]);
}
}
touch("({$maxIndex}){$fileName}");
}