Cocos2d-x Tutorial 3: Converting files and decompressing zip with PHP or DOS batch commands

Source: Internet
Author: User
Tags explode ziparchive

In the cocos2d-x use, you need to constantly convert files and compression or decompression files, if the whole manual to do, too cumbersome, and error prone. I'm going to put some of it in the batch and use it for everyone.

  • Automatically rename dat files to gz,dos batch by numeric sort
  • @echo off&setlocal enabledelayedexpansion
    Color 0a
    Echo%date%%time%
    echo is renaming files in bulk ...
    Set A=1
    for/f "delims="%%i in (' dir/b *.dat ') does (
    If not "%%~ni" = = "%~n0" (
    If!a! LSS (ren "%%i" "0!a!"). GZ ") Else (ren"%%i ""!a!. GZ ")
    set/a a+=1
    )
    )
    set/a a-=1
    echo rename complete, rename%a% files.
    Pause
  • PHP unzip the zip. Configure PHP.ini to use this PHP extension class, Need (PHP 5 >= 5.2.0, PECL zip >= 1.1.0), some methods require PHP 5.2.+, and php.ini configuration support zip
    For the win system, simply remove the comment for the php_zip.dll extension, and then restart the HTTP service (IIS or Apache) to
  • $zip = new Ziparchive;
    $res = $zip->open (' AM. ZIP ');
    if ($res = = = TRUE) {
    echo ' OK ';
    Unzip to test folder
    $zip->extractto (' AM ');
    $zip->close ();
    } else {
    Echo ' failed, code: '. $res;
    }
  • PHP Loop Rename
  • $s =explode ("\ n", Trim (' dir/b d:\\tmp\\ '));//Get all file names under the path
    Print_r ($s);
    foreach ($s as $rs)
    {
    $name =explode (".", $rs);
    $file _name= $name [0];//Gets the name of the folder to be created
    mkdir ("e:/11-2/caps/$file _name");//Create Folder
    Rename (' d:/tmp/'. $rs, "d:/tmp/$file _name". GZ ");//move and rename files

    }
  • PHP Loop Self-extracting
  • $s =explode ("\ n", Trim (' dir/b d:\\tmp\\ '));//Get all filenames under this path
    //print_r ($s);
    foreach ($s as $rs)
    {
        $name =explode (".", $rs);
        $file _name= $name [0];//get the folder name to create
       //mkdir ("e:/11-2/caps/$file _name");// Create folder
        rename (' d:/tmp/'. $rs, "d:/tmp/$file _name". GZ ");//move and rename files
        //
         $zip = new Ziparchive;
         $tmpFile = $file _name. ". GZ ";
         $res = $zip->open ($tmpFile);
        if ($res = = = TRUE) {
            echo ' OK ';
            //extract to test folder
             $zip->extractto ($ file_name);
             $zip->close ();
        } else {
            echo $tmpFile. ' Failed, code: '. $res. " <br> ";
        }

    }
  • php loop to read the directory and then automatically unzip
  • $s =explode ("\ n", Trim (' dir/b d:\\tmp\\ '));//Get all filenames under this path
    //print_r ($s);
    foreach ($s as $rs)
    {
        $name =explode (".", $rs);
        $file _name= $name [0];//get the folder name to create
       //mkdir ("e:/11-2/caps/$file _name");// Create folder
        rename (' d:/tmp/'. $rs, "d:/tmp/$file _name". GZ ");//move and rename files
        //
         $zip = new Ziparchive;
         $tmpFile = $file _name. ". GZ ";
         $res = $zip->open ($tmpFile);
        if ($res = = = TRUE) {
            echo ' OK ';
            //extract to test folder
             $zip->extractto ($ file_name);
             $zip->close ();
        } else {
            echo $tmpFile. ' Failed, code: '. $res. " <br> ";
        }

    }
  • Copy a file to another file under a folder of the same name. For example, effect01.png copy to sheet.png under the effect01 directory
  • <?php

    $fnum = 0;
    $path = "d://wamp/www/my/"; # #路径
    $handle = @ opendir ($path) or Die ("Cannot open Directory");
    $arr =array (); # #定义保存存在的文件
    $imgs =array ("1.jpg", "11.jpg");//test if you match these 2 files
    if ($handle) {
    while (false!== ($file = Readdir ($handle))) {//existence file
    if ($file! = '. ' && $file! = ' ... ') {# #不为:
    $img =substr ($file, Strripos ($file, ".") +1);//Determine suffix name
    if ($img = = "PVR") {
    $v = $file. ". PNG ";
    $newname = "$file/sheet.png";
    if (rename ($v, $newname))
    {
    Echo ' successfully will '. $v. ' Rename '. $newname. ' <br/> ';
    }
    Delete old files
    $oldFile = "$file/SHEET.PVR";
    if (unlink ($oldFile)) {
    echo "successfully". $oldFile. " Delete! <br/> ";
    }
    //}
    $fnum + +;
    }
    }
    }
    Closedir ($handle);//close file stream.
    ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.