BatchFileRename Libraryv1.0

Logging

BatchFileRename provides the ability to save a log file contains the successfully renamed files and their original names, the log file may be used later to restore the renamed files to their original names by using the renameFromLogFile() method.



Usage Examples

Creating Log File

A simple example of how to save a log file for the the successfully renamed files.

Code:
// Include BatchFileRename class file
require ("path/to/BatchFileRename.php");

// Create a new class instance
$obj = new BatchFileRename();

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

// Define the renaming rules
$obj->setRenameRules(array(
    
"prefix" => "Coldplay - " 
    
));

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

// Save a log file with the successfully renamed files 
$obj->createLogFile("path/to/log.txt");
Result:
The created log file will be something like this:
Cemeteries Of London.mp3|Coldplay - Cemeteries Of London.mp3
Death And All His Friends.mp3|Coldplay - Death And All His Friends.mp3
Lost.mp3|Coldplay - Lost.mp3
The Escapist.mp3|Coldplay - The Escapist.mp3
Viva La Vida.mp3|Coldplay - Viva La Vida.mp3

Renaming From A Previously Created Log File

A simple example of how to rename files based on a previously created log file.

Code:
// Include BatchFileRename class file
require ("path/to/BatchFileRename.php");

// Create a new class instance
$obj = new BatchFileRename();

// Define the directoryPath
$obj->setFileSetOptions(array("directoryPath" => "/path/to/directory/", ));

// Rename files based on the previously created log file
$bfr->renameFromLogFile("path/to/log.txt"true);
Result:
The files will be renamed back to its original names:
Files Before RenameFiles After Rename
Coldplay - Cemeteries Of London.mp3Cemeteries Of London.mp3
Coldplay - Death And All His Friends.mp3Death And All His Friends.mp3
Coldplay - Lost.mp3Lost.mp3
Coldplay - The Escapist.mp3The Escapist.mp3
Coldplay - Viva La Vida.mp3Viva La Vida.mp3