douxian0279 2018-02-03 02:14
浏览 40
已采纳

递归文件和目录列出github

I`m looking for a way to list all files and directories of a github release

For example:

root
-> x.txt
-> folder1
   -> folder2
      -> file-0.txt
   -> file-1.txt

would return:

root/x.txt
root/folder1/file-1.txt
root/folder1/folder2/file-0.txt

Is there a way to do this directly with github api? if not with php and api?

  • 写回答

2条回答 默认 最新

  • dongxu7408 2018-02-08 03:27
    关注

    In PHP:

    function github_curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token  XXX_TOKEN"));
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    return curl_exec($ch);
    }
    
    $cache = github_curl("https://api.github.com/repos/LucLaverdure/Wizard.Build/releases/latest?client_secret=XXX_SECRET");
    $cache = json_decode($cache, true);
    $cache_file = $cache["zipball_url"];
    
    // get zip file, build it if new
    if (!file_exists(dirname(__FILE__)."/cache/".basename($cache_file).".zip")) {
        $cache_download = github_curl($cache_file);
        file_put_contents(dirname(__FILE__)."/cache/".basename($cache_file).".zip", $cache_download);
    }
    
    
    // list files within zip file (FTP ONLY)
    $zip = new ZipArchive; 
    if ($zip->open(dirname(__FILE__)."/cache/".basename($cache_file).".zip") == TRUE) {
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $filename = $zip->getNameIndex($i);
         echo $filename."<br>";
     }
    }
    

    Voila!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line