diff options
Diffstat (limited to 'lib/helper.php')
-rwxr-xr-x | lib/helper.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/helper.php b/lib/helper.php index c33db5f10fe..412f0e6b764 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -492,4 +492,32 @@ class OC_Helper { } } } + + /** + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ + public static function buildNotExistingFileName($path, $filename) + { + if ($pos = strrpos($filename, '.')) { + $name = substr($filename, 0, $pos); + $ext = substr($filename, $pos); + } else { + $name = $filename; + } + + $newpath = $path . '/' . $filename; + $newname = $filename; + $counter = 2; + while (OC_Filesystem::file_exists($newpath)) { + $newname = $name . ' (' . $counter . ')' . $ext; + $newpath = $path . '/' . $newname; + $counter++; + } + + return $newname; + } } |