File Utilities Class

File Utilities Class

This class can be used to retrieve information from files.

Description

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:

  1. Date Accessed
  2. Modified Date
  3. Created Date
  4. File Size
  5. File Name

Other Features

  • 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.

New Instance

$obj = new fileUtilities();

Set Path

Using a different path than default:

$obj->Set_Path("Directory Path");

Filtering

Setting a filter allows you to retrieve files by their extension

$obj->Set_Filter(".php");

Retrieving Files Info

To retrieve a list of all the files inside a directory with their respective information, you can use the following function.

$obj->Get_FilesInfo()

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.

$obj->Group_byExt();

Keys:

  • 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.

$obj->Set_Ext($file,$ext);

Note: This function does not create a new file. It returns a string.

Count Files

Returns the number of files in a directory

$obj->File_Count();

Get Directory Path

Returns a directory’s path.

$obj->Get_Directory();

Writable

Verifies if the file is Writable. Returns True or False

$obj->Writable("File Name");

Readable

Verifies if the file is Readable. Returns True or False

$obj->Readable(" file name");

File Exists

Searches for a file inside a directory.

$obj->Is_FileIn(" file name");

 Download:

https://github.com/alvarezr/File-Utilities

This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>