BatchFileRename Libraryv1.0

FileSet Filters

FileSet Filters is used to tell BatchFileRename what files to rename and filter undesired files from being renamed. FileSet Filters can be defined in two ways:

Options Table
Option Type Description Usage
directoryPath string Contains the full absolute path of the directory which its contents will be renamed.
includeExtensions array Used to include a specific file extension(s) in the fileSet.
excludeExtensions array Used to exclude a specific file extension(s) from the fileSet.
minimumFileSize integer Used to exclude files smaller than this size (in bytes).
maximumFileSize integer Used to exclude files larger than this size (in bytes).
minimumFileNameLength integer Used to exclude file names that lessens a specific length.
maximumFileNameLength integer Used to exclude file names that exceeds a specific length.
regexPattern string Used to exclude files using a regular expression pattern which applied to the filename. Usage
callback callback Used to filter files from the fileSet using a user-defined callback which take only one paramater which is an object containing file information. Usage
fileSetSize integer Used to limit the number of files in the fileSet. In another way it will force BatchFileRename not to rename all the files within the directory, it will rename just the defined number of files. This is useful when dealing with directories with large number of files.

Options Usage Examples

regexPattern

Used to exclude files using a regular expression pattern which applied to the filename.

Code:
$obj->setFileSetOptions(array(
    
"directoryPath" => "/path/to/directory/"
    
"regexPattern" => "^jos_[^]$"
    
));
Result:
Includes only file names that starts with "jos_"

callback

Used to filter files from the fileSet using a user-defined callback which take only one paramater which is an object containing file information.

Code:
/**
 * A custom callback for excluding files named "test".
 *
 * The $fileinfo paramater contains file informations like:
 *  $fileinfo->path         The file path
 *  $fileinfo->name         The file name
 *  $fileinfo->basename     The file name without the extension
 *  $fileinfo->extension    The file extension
 *  $fileinfo->size         The file size
 *
 * @param   object  $fileinfo    Object containing file information
 * @return  bool    If FALSE the file will be excluded, TRUE the file will be included
 */
function myCustomCallback($fileinfo){

    if(
$fileinfo->basename == "test"){
        return 
false;
    }
    
    return 
true;
}

$obj->setFileSetOptions(array(
    
"directoryPath" => "/path/to/directory/"
    
"callback" => "myCustomCallback"
    
));
Result:
Excludes any file wich its basename is "test" regardless of file extension, eg. test.txt, test.html, test.jpeg