PHP Classes

File: examples/simple.autoNumber.php

Recommend this page to a friend!
  Classes of Mohamed Elkholy   Batch File Rename   examples/simple.autoNumber.php   Download  
File: examples/simple.autoNumber.php
Role: Example script
Content type: text/plain
Description: demo file
Class: Batch File Rename
Rename multiple files according to flexible rules
Author: By
Last change: updated to v1.0 build 29
Date: 12 years ago
Size: 1,282 bytes
 

Contents

Class file image Download
<?php
/*
 * A simple example that renames a set of files by auto-numbering them with a prefix.
 *
 * @package BatchFileRename
 * @author Mohamed ELkholy <mkh117@gmail.com>
 * @copyright Copyright (c) 2012 Mohamed Elkholy
 * @version SVN: $Id: simple.autoNumber.php 5 2012-04-17 18:53:36Z admin $
 * @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
 * @link http://www.phpclasses.org/package/7472
 */

// Include BatchFileRename class file
require ("../src/BatchFileRename.php");

// Create a new class instance and enable simulation mode
$batchFileRename = new BatchFileRename(array(
   
"simulationMode" => true,
    ));

// Define the fileSet filters
$batchFileRename->setFileSetOptions(array(
   
"directoryPath" => "/path/to/directory/",
   
"includeExtensions" => array("txt"),
    ));

// Define the renaming rules
$batchFileRename->setRenameRules(array(
   
"prefix" => "<##> - ",
    ));

// Rename the files
$batchFileRename->rename();

echo
"<pre>";

echo
"Successfully renamed files:";
print_r($batchFileRename->getResultArray());

// Check if an error occurs while renaming the files
if($batchFileRename->isError()){
    echo
"Some files were not renamed!";
   
print_r($batchFileRename->getErrorsArray());
}

echo
"</pre>";