Skip to content

Instantly share code, notes, and snippets.

@coquer
Last active August 29, 2015 14:20
Show Gist options
  • Save coquer/22f2f2c14bffd1da8c77 to your computer and use it in GitHub Desktop.
Save coquer/22f2f2c14bffd1da8c77 to your computer and use it in GitHub Desktop.
<?php
function blobR($pattern, $flags){
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, blobR($dir.'/'.basename($pattern), $flags));
}
return $files;
}
function copyfiles($pattern, $des_dir, $flags = 0){
createdir($des_dir);
$arr = blobR($pattern, $flags);
foreach ($arr as $key => $value) {
$file = getfilename($value);
copy($value, $des_dir . '/' . $file);
}
}
function getfilename($filename){
$file = substr($filename, strrpos($filename, '/') + 1);
return $file;
}
function createdir($des_dir){
if (!file_exists($des_dir)) {
mkdir($des_dir, 0777, true);
}
}
copyfiles('*.epub', 'allbooks');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment