method move documentation in bbn\File\Dir
Moves a file or directory to a new location
Example
\bbn\X::dump(\bbn\File\Dir::move("/home/data/test/Folder/image.png","/home/data/test/Folder_test/image.png"));
\\ (string) "image.png"
\bbn\X::dump(\bbn\File\Dir::move("/home/data/test/Folder/image.png","/home/data/test/Folder_test/Intro/image.png"));
\\ (string) "image.png"
\bbn\X::dump(\bbn\File\Dir::move("/home/data/test/Folder","/home/data/test/Folder_test", true));
\\ (string) "Folder_test"
\bbn\X::dump(\bbn\File\Dir::move("/home/data/test/Folder","/home/data/test/Folder_test", "_n", 3));
\\ (string) "Folder_test_n001"
function($orig, $dest, $st = '_v', $length = 0)
{
if ( file_exists($orig) && self::createPath(X::dirname($dest)) ){
if ( file_exists($dest) ){
if ( $st === true ){
self::delete($dest);
}
else{
$i = 1;
while ( $i ){
$dir = X::dirname($dest).'/';
$file_name = bbn\Str::fileExt($dest, 1);
$file = $file_name[0].$st;
if ( $length > 0 ){
$len = \strlen(bbn\Str::cast($i));
if ( $len > $length ){
return false;
}
$file .= str_repeat('0', $length - $len);
}
$file .= bbn\Str::cast($i);
if ( !empty($file_name[1]) ){
$file .= '.'.$file_name[1];
}
$i++;
if ( !file_exists($dir.$file) ){
$dest = $dir.$file;
$i = false;
}
}
}
}
if ( rename($orig, $dest) ){
return true;
}
}
return false;
}
Moves a file or directory to a new location BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions