cocos2d-x教程3:用php或DOS批處理命令來轉換檔和解壓縮zip

來源:互聯網
上載者:User

標籤:cocos2d-x教程   dos   php   批處理   壓縮   

在cocos2d-x使用中,需要不停的轉換檔和壓縮或解壓檔案,如果全人工來做,太麻煩了,且容易出錯。我現在把一些用的到批處理貼出來,供大家使用

  • 自動把dat檔案按數字排序重新命名gz,DOS批處理
  • @echo off&setlocal EnableDelayedExpansion
    color 0a
    echo %date% %time%
    echo 正在批量重新命名檔案......
    set a=1
    for /f "delims=" %%i in (‘dir /b *.dat‘) do (
        if not "%%~ni" == "%~n0" (
            if !a! LSS 10 (ren "%%i" "0!a!.gz")else (ren "%%i" "!a!.gz")
            set /a a+=1
        )
    )
    set /a a-=1
    echo 重新命名完成,共重新命名%a%個檔案。
    pause
  • php解壓zip.配置php.ini 要使用該PHP擴充類,需要(PHP 5 >= 5.2.0, PECL zip >= 1.1.0),部分方法需要 PHP 5.2.+,且php.ini配置支援zip
    對於win系統,直接去掉php_zip.dll 擴充的注釋,然後重啟http服務(IIS或Apache)即可
  • $zip = new ZipArchive;
    $res = $zip->open(‘AM.ZIP‘);
    if ($res === TRUE) {
        echo ‘ok‘;
        //解壓縮到test檔案夾
        $zip->extractTo(‘AM‘);
        $zip->close();
    } else {
        echo ‘failed, code:‘ . $res;
    }
  • php迴圈重新命名
  • $s=explode("\n",trim(`dir/b d:\\tmp\\`));//擷取該路徑下所有檔案名稱
    //print_r($s);
    foreach($s as $rs)
    {
        $name=explode(".",$rs);
        $file_name=$name[0];//擷取要建立的檔案夾名字
        //mkdir("E:/11-2/caps/$file_name");//建立檔案夾
        rename(‘d:/tmp/‘.$rs,"d:/tmp/$file_name".".gz");//移動並重新命名檔案

    }
  • php迴圈自解壓
  • $s=explode("\n",trim(`dir/b d:\\tmp\\`));//擷取該路徑下所有檔案名稱
    //print_r($s);
    foreach($s as $rs)
    {
        $name=explode(".",$rs);
        $file_name=$name[0];//擷取要建立的檔案夾名字
        //mkdir("E:/11-2/caps/$file_name");//建立檔案夾
        rename(‘d:/tmp/‘.$rs,"d:/tmp/$file_name".".gz");//移動並重新命名檔案
        //
        $zip = new ZipArchive;
        $tmpFile=$file_name.".gz";
        $res = $zip->open($tmpFile);
        if ($res === TRUE) {
            echo ‘ok‘;
            //解壓縮到test檔案夾
            $zip->extractTo($file_name);
            $zip->close();
        } else {
            echo $tmpFile.‘failed, code:‘ . $res."<br>";
        }

    }
  • php迴圈讀取目錄,然後自動解壓
  • $s=explode("\n",trim(`dir/b d:\\tmp\\`));//擷取該路徑下所有檔案名稱
    //print_r($s);
    foreach($s as $rs)
    {
        $name=explode(".",$rs);
        $file_name=$name[0];//擷取要建立的檔案夾名字
        //mkdir("E:/11-2/caps/$file_name");//建立檔案夾
        rename(‘d:/tmp/‘.$rs,"d:/tmp/$file_name".".gz");//移動並重新命名檔案
        //
        $zip = new ZipArchive;
        $tmpFile=$file_name.".gz";
        $res = $zip->open($tmpFile);
        if ($res === TRUE) {
            echo ‘ok‘;
            //解壓縮到test檔案夾
            $zip->extractTo($file_name);
            $zip->close();
        } else {
            echo $tmpFile.‘failed, code:‘ . $res."<br>";
        }

    }
  • 把一個檔案拷貝到同名檔案夾下的另外一個檔案。例如effect01.png 拷貝到effect01目錄下的sheet.png
  • <?php

                $fnum = 0;
                $path="d://wamp/www/my/";##路徑
                $handle = @ opendir($path) or die("無法開啟目錄");
                $arr=array();##定義儲存存在的檔案
                $imgs=array("1.jpg","11.jpg");//測試假使匹配這2個檔案
                if($handle){
                        while (false !== ($file = readdir($handle))){//存在檔案
                                if($file != ‘.‘ && $file != ‘..‘){##不為..
                                        //$img=substr($file,strripos($file,".")+1);//判斷尾碼名
                                        //if($img=="pvr"){                                      
                                           $v=$file.".png";
                                           $newname="$file/sheet.png";
                                           if(rename($v,$newname))
                                            {
                                              echo ‘成功將‘.$v.‘重新命名‘.$newname.‘<br />‘;
                                            }
                                            //刪除舊檔案
                                            $oldFile="$file/sheet.pvr";
                                            if(unlink($oldFile)){
                                                echo "成功將".$oldFile."刪除!<br />";
                                            }
                                        //}
                                        $fnum++;
                                }
                        }
                }
                closedir($handle);//關閉檔案流.
    ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.