PHP Classes

File: examples/simple.fixedFilename.php

Recommend this page to a friend!
  Classes of Mohamed Elkholy   Batch File Rename   examples/simple.fixedFilename.php   Download  
File: examples/simple.fixedFilename.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: 11 years ago
Size: 1,283 bytes
 

Contents

Class file image Download
<?php
/*
 * A simple example that renames a set of files by using a fixed file name.
 *
 * @package BatchFileRename
 * @author Mohamed ELkholy <mkh117@gmail.com>
 * @copyright Copyright (c) 2012 Mohamed Elkholy
 * @version SVN: $Id: simple.fixedFilename.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(
   
"fixedFileName" => "file<##>",
    ));

// 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>";