You are here

function file_create_filename in Coder 7.2

Same name and namespace in other branches
  1. 5.2 scripts/coder_format/coder_format.php \file_create_filename()
  2. 6.2 scripts/coder_format/coder_format.php \file_create_filename()
  3. 6 scripts/coder_format/coder_format.php \file_create_filename()
  4. 7 scripts/coder_format/coder_format.php \file_create_filename()

Create a full file path from a directory and filename. If a file with the specified name already exists, an alternative will be used.

Parameters

$basename string filename:

$directory string directory:

1 call to file_create_filename()
file_destination in scripts/coder_format/coder_format.php
Determines the destination path for a file depending on how replacement of existing files should be handled.

File

scripts/coder_format/coder_format.php, line 284
Coder format shell invocation script.

Code

function file_create_filename($basename, $directory) {
  $dest = $directory . '/' . $basename;
  if (file_exists($dest)) {

    // Destination file already exists, generate an alternative.
    // Always append '.coder.orig' (allows multiple undos). 23/01/2008 sun
    $name = $basename;
    $counter = 0;
    do {
      $dest = $directory . '/' . $name . str_repeat('.coder.orig', $counter++);
    } while (file_exists($dest));
  }
  return $dest;
}