Php batch rename

Source: Internet
Author: User

Php batch rename this program can be divided into simple single file rename, plus getfile to achieve batch Rename of files, $ path is the directory you want to rename, it can rename the description of the specified file type in the specified directory in batches. Very easy to use.

Batch rename php tutorials
This program can be divided into simple single file name duplication, plus getfile to achieveBatch File rename$ Path is the directory you want to rename. It can rename the description of the specified file type in the specified directory in batch. Very easy to use.
*/

$ Format = 'php ';
$ Path = 'www .bkjia.com /';
$ Files = getfile ($ path, $ format );

Foreach ($ files as $ v)
{
$ TV = basename ($ v );
List ($ name, $ ext) = explode ('.', $ TV );
$ Newname = $ path. time (). mt_rand (1,10000). '.'. $ ext;
If (rename ($ v, $ newname ))
{
Echo '. $ v.' is successfully renamed '. $ newname.' <br/> ';
}
}

Function getfile ($ path, $ format)
{
$ Dirs = array ();
Foreach (glob ("$ path *") as $ d)
{
$ Tmp = explode ('.', $ d );
$ K = end ($ tmp );
If (is_file ($ d) & ($ k = strtolower ($ format )))
{
$ Dirs [] = $ d;
}
}
Return $ dirs;
}

/*
Rename/12819320034756. php rename/12819402065296.php
Rename/12819320036890. php rename/12819402067216.php
Rename/12819320037133. php rename/12819402067656.php

This site original tutorials, graves Indicate source http://www.bkjia.com/phper/php.html
*/
?>


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.