Skip to content

Commit

Permalink
Update fs:rename
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed May 5, 2016
1 parent ef19293 commit ccb4662
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Command/FsRenameCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,35 @@ public function configure()
->addArgument(
'src',
InputArgument::REQUIRED,
'source filename or directory'
'Source filename or directory'
)
->addArgument(
'dst',
'dest',
InputArgument::REQUIRED,
'destination filename/directory'
)
'Destination filename or directory'
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$src = $input->getArgument('src');
$dst = $input->getArgument('dst');
$dest = $input->getArgument('dest');

$output->WriteLn("Fs Rename From: $src to $dst ");
$output->WriteLn("Fs Rename From: $src to $dest ");

if (is_dir($src)) {
$type = 'Directory';
} else {
$type = 'File';
}
if (!file_exists($src)) {
throw new RuntimeException("Source ".$type." not exists: " . $src);
throw new RuntimeException("Source does not exist: " . $src);
}
if (file_exists($dest)) {
throw new RuntimeException("Destination already exist: " . $dest);
}
if (!rename($src, $dst)) {
throw new RuntimeException("Rename failed: " . $src .' to ' .$dst);
if (!rename($src, $dest)) {
throw new RuntimeException("Rename failed: " . $src .' to ' .$dest);
}
}
}

0 comments on commit ccb4662

Please sign in to comment.