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.
A simple example of how to save a log file for the the successfully renamed files.
// 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");
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
A simple example of how to rename files based on a previously created log file.
// 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);
Files Before Rename | Files After Rename |
---|---|
Coldplay - Cemeteries Of London.mp3 | Cemeteries Of London.mp3 |
Coldplay - Death And All His Friends.mp3 | Death And All His Friends.mp3 |
Coldplay - Lost.mp3 | Lost.mp3 |
Coldplay - The Escapist.mp3 | The Escapist.mp3 |
Coldplay - Viva La Vida.mp3 | Viva La Vida.mp3 |