File Utilities Class
This class can be used to retrieve information from files.
fileUtilities allows you to generate a list of files within a directory with information such as a file name, file ext, etc…
Information that can be retrieved:
- Date Accessed
- Modified Date
- Created Date
- File Size
- File Name
- Number of files inside a directory.
- Filters files by extension.
- Verifies if the file exists.
- Verifies if the file is readable or writable.
How to Use
The default path is going to be where the file is located. Using the method Set_Path($path) you can specify the directory path.
$obj = new fileUtilities();
Using a different path than default:
Setting a filter allows you to retrieve files by their extension
Retrieving Files Info
To retrieve a list of all the files inside a directory with their respective information, you can use the following function.
This function returns an associative array with keys:
- Name: File Name
- Ext : File Extension
- Accessed : Last Accessed Date
- Modified : Last Modified Date
- Created : Created Date
- Size : File Size
For a single file, use the function below:
$obj->Get_Finfo ("File Name");
Group by Ext
Returns an associative array.
- Count : Count of file by extension.
- Ext : Extension Group.
- Name : List of file name.
Change File Ext
This method allows you to change the extension of the file that is being passed through its parameter.
Note: This function does not create a new file. It returns a string.
Returns the number of files in a directory
Get Directory Path
Returns a directory’s path.
Verifies if the file is Writable. Returns True or False
Verifies if the file is Readable. Returns True or False
$obj->Readable(" file name");
Searches for a file inside a directory.
$obj->Is_FileIn(" file name");