最近在做备份SQL,看了一些资料后,闲暇时间搞了一个脚本,希望能帮到需要的朋友。还请各大牛指正,本想做一个继续无限浏览子目录点击并显示内容。时间不足,希望有朋友能完善!
/*
* 列出目录下的所有文件
* @param str $path 目录
* @param array $exts 后缀
* @param bool $dir 是否开启显示下级目录
* @return array 返回路径数组
* $dirtoscan = ("./databack");
* $exts=array('sql');
* print_r(_listfile($dirtoscan,$exts));
*/
function _listfile($path,$exts=array(),$dir=false){
$dir_list=dir_list($path);
$str=array();
foreach ($dir_list as $k){
if($dir){
if (is_file(_musbcn("utftogbk", $k))) {
if (in_array(_Fileexts(3, $k), $exts)) {
$str[] = array('type' => 'files', 'url' => $k, 'file' => _Fileexts(2, $k));
}
} else {
$str[] = array('type' => 'dirs', 'url' => $k);
}
}else{
if (in_array(_Fileexts(3, $k), $exts)) {
$str[] = array('type' => 'files', 'url' => $k, 'file' => _Fileexts(2, $k));
}
}
}
return json_encode($str);
}
/*
* 获取指定路径下所有文件包含文件夹
* @param str $path 指定路径
* @param array $list 列出文件与文件夹信息
* @return array 返回路径数组
*/
function dir_list($path,$list = array()) {
$path = dir_path($path);
$files = glob($path . '*');
foreach($files as $v) {
if (is_file($v)) {
$list[] = _musbcn("gbktoutf", $v);
$list = dir_list($v, $list);
} else {
$list[] = _musbcn("gbktoutf", $v);
}
}
return $list;
}
/*
* 路劲转换
* param str $path 文件夹路径
* @return str 返回路径
*/
function dir_path($path) {
$path = str_replace('\\', '/', $path);
if (substr($path, -1) != '/') $path = $path . '/';
return $path;
}
该文章提供了一个用于备份SQL文件的脚本,并能列出指定目录下的所有文件,特别是SQL扩展名的文件。脚本还包括了基础的目录遍历功能,但作者希望有人能进一步完善以实现无限递归展示子目录内容。
1264

被折叠的 条评论
为什么被折叠?



