zoukankan      html  css  js  c++  java
  • 在属性方法内写匿名方法 递归文件

        #货物当前所有的版本文件夹
        public function getDirList()
        {
            $root_path = Env::get('root_path');
            $fileDirectory = $root_path . '/public/codeZip';
            $newFile = [];
            $tree = function ($fileDirectory, $newFile) use (&$treet) {
                if (is_dir($fileDirectory)) {
                    $file = scandir($fileDirectory, 1);
                    if ($file) {
                        foreach ($file as $key => $value) {
                            if ($value  != '.' && $value != '..') {
                                if (is_dir($fileDirectory . '/' . $value)) {
                                    return $treet($fileDirectory . '/' . $value, $newFile);
                                }
                                if ($value !== '.' && $value !== '..') {
                                    $newFile[] = $value;
                                }
                            }
                        }
                        return $newFile;
                    }
                }
                return [];
            };
            $dirList = $greet($fileDirectory, $newFile);
            return $this->returnData(0, '成功', $dirList);
        }



      #按修改时间倒叙
        public function getDirList()
        {
            $root_path = Env::get('root_path');
            $fileDirectory = $root_path . '/public/codeZip';
            $newFile = [];
            $greet = function ($fileDirectory, $newFile, &$seconds) use (&$greet) {
                if (is_dir($fileDirectory)) {
                    $file = scandir($fileDirectory, 1);
                    if ($file) {
                        foreach ($file as $key => $value) {
                            if ($value  != '.' && $value != '..') {
                                if (is_dir($fileDirectory . '/' . $value)) {
                                    return $greet($fileDirectory . '/' . $value, $newFile, $seconds);
                                }
                                if ($value !== '.' && $value !== '..') {
                                    $newFile[$seconds]['fileName'] = $value;
                                    $newFile[$seconds]['uTime'] = filemtime($fileDirectory . '/' . $value);
                                }
                                $seconds += 1;
                            }
                        }
                        return $newFile;
                    }
                }
                return [];
            };
            $seconds = 0;

            $dirList = $greet($fileDirectory, $newFile, $seconds);
            $uTime = array_column($dirList, 'uTime');
            array_multisort($uTime, SORT_DESC, $dirList);
            $dirList = array_column($dirList, 'fileName');
            return $this->returnData(0, '成功', $dirList);
        }
     
  • 相关阅读:
    Linux学习之探索文件系统
    `设计模式之代理模式
    `设计模式之单例模式
    `设计模式之工厂模式
    浅谈系列之 javascript原型与对象
    Javascript基础
    jQuery效率提升建议
    CSS基础知识汇总
    CSS-float详解,深入理解clear:both[转+部分原创]
    HTML基础知识汇总
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/14376204.html
Copyright © 2011-2022 走看看