Cocos2d-x tutorial 3: Use php or DOS batch commands to convert files and decompress zip

Source: Internet
Author: User
Tags decompress zip ziparchive

In the use of the cocos2d-x, the need to constantly convert files and compression or decompression files, if the whole manual to do, too much trouble, and easy to error. Now, I will post some of the items used for Batch Processing for your use.

  • Automatically rename dat files by number in gz and DOS batch processing
  • @ Echo off & setlocal EnableDelayedExpansion
    Color 0a
    Echo % date % time %
    Echo is renaming files in batches ......
    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 + = 1
    )
    )
    Set/a-= 1
    Echo is renamed. % a % files are renamed.
    Pause
  • Php zip.Configure php. ini needs to use this PHP extension class (PHP 5> = 5.2.0, PECL zip> = 1.1.0), and some methods require PHP 5.2. +, and php. ini configuration supports zip
    For the win system, remove the php_zip.dll extension comments and restart the http service (IIS or Apache ).
  • $ Zip = new ZipArchive;
    $ Res = $ zip-> open ('am. zip ');
    If ($ res = TRUE ){
    Echo 'OK ';
    // Decompress the package to the test folder.
    $ Zip-> extracloud ('am ');
    $ Zip-> close ();
    } Else {
    Echo 'failed', code: '. $ res;
    }
  • Php loop rename
  • $ S = explode ("\ n", trim ('dir/B d: \ tmp \ '); // obtain all file names in this path
    // Print_r ($ s );
    Foreach ($ s as $ rs)
    {
    $ Name = explode (".", $ rs );
    $ File_name = $ name [0]; // obtain the name of the folder to be created
    // Mkdir ("E:/11-2/caps/$ file_name"); // create a folder
    Rename ('d:/tmp/'. $ rs, "d:/tmp/$ file_name". ". gz"); // move and rename the file

    }
  • Php self-extracting
  • $ S = explode ("\ n", trim ('dir/B d: \ tmp \ '); // obtain all file names in this path
    // Print_r ($ s );
    Foreach ($ s as $ rs)
    {
    $ Name = explode (".", $ rs );
    $ File_name = $ name [0]; // obtain the name of the folder to be created
    // Mkdir ("E:/11-2/caps/$ file_name"); // create a folder
    Rename ('d:/tmp/'. $ rs, "d:/tmp/$ file_name". ". gz"); // move and rename the file
    //
    $ Zip = new ZipArchive;
    $ TmpFile = $ file_name. ". gz ";
    $ Res = $ zip-> open ($ tmpFile );
    If ($ res = TRUE ){
    Echo 'OK ';
    // Decompress the package to the test folder.
    $ Zip-> extraceid ($ file_name );
    $ Zip-> close ();
    } Else {
    Echo $ tmpFile. 'failed', code: '. $ res. "<br> ";
    }

    }
  • Php cyclically reads the Directory and automatically decompress it.
  • $ S = explode ("\ n", trim ('dir/B d: \ tmp \ '); // obtain all file names in this path
    // Print_r ($ s );
    Foreach ($ s as $ rs)
    {
    $ Name = explode (".", $ rs );
    $ File_name = $ name [0]; // obtain the name of the folder to be created
    // Mkdir ("E:/11-2/caps/$ file_name"); // create a folder
    Rename ('d:/tmp/'. $ rs, "d:/tmp/$ file_name". ". gz"); // move and rename the file
    //
    $ Zip = new ZipArchive;
    $ TmpFile = $ file_name. ". gz ";
    $ Res = $ zip-> open ($ tmpFile );
    If ($ res = TRUE ){
    Echo 'OK ';
    // Decompress the package to the test folder.
    $ Zip-> extraceid ($ file_name );
    $ Zip-> close ();
    } Else {
    Echo $ tmpFile. 'failed', code: '. $ res. "<br> ";
    }

    }
  • Copy an object to another object in a folder with the same name. For example, when t01.png is created, go to sheet.png under the "t01" directory.
  • <? Php

    $ Fnum = 0;
    $ Path = "d: // wamp/www/my/"; # path
    $ Handle = @ opendir ($ path) or die ("cannot open directory ");
    $ Arr = array (); # define the saved object
    $ Imgs = array ("1.jpg"," 11.jpg"); // test if the two files match
    If ($ handle ){
    While (false! ==( $ File = readdir ($ handle) {// file exists
    If ($ file! = '.' & $ File! = '..') {# Not ..
    // $ Img = substr ($ file, strripos ($ file, ".") + 1); // judge the suffix
    // If ($ img = "pvr "){
    $ V = $ file. ". png ";
    $ Newname = "$ file/sheet.png ";
    If (rename ($ v, $ newname ))
    {
    Echo '. $ v.' is successfully renamed '. $ newname.' <br/> ';
    }
    // Delete the old file
    $ OldFile = "$ file/sheet. pvr ";
    If (unlink ($ oldFile )){
    Echo ". $ oldFile." deleted successfully! <Br/> ";
    }
    //}
    $ Fnum ++;
    }
    }
    }
    Closedir ($ handle); // close the file stream.
    ?>

Related Article

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.