Recommend this page to a friend! |
![]() ![]() |
Info | ![]() |
![]() |
![]() ![]() |
Reputation | Support forum (1) | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2014-06-12 (2 years ago) ![]() | Not yet rated by the users | Total: 142 | All time: 8,224 This week: 872![]() |
Version | License | PHP version | Categories | |||
path-name 1.0 | Public Domain | 5.3 | Files and Folders |
Description | Author | |
This class can manipulate paths of files and directories. |
path.php contains class file\path. This class facilitates the manipulation of filenames; effectively it is a wrapper of PHP's built-in pathinfo() function.
modifier.php contains an example class that uses file\path.
phpdoc.dist.xml contains configuration information to generate automatic documentation using the phpDocumentor PEAR package.
tests/path_test.php contains some tests that can be run using phpunit:
$ phpunit tests/path_test.php
This test file also gives some examples of how the file\path class can be used.
The aim of this class is to make filename manipulation easy and intuitive.
Example 1: To rename a file in the current directory from foo.txt to foo.bak.
<?php require 'path.php';
$filename = 'foo.txt'; $backupfilename = new file\path($filename); $backupfilename->extension = 'bak'; rename($filename, $backupfilename); ?>
Example 2: to move a file to the system temporary directory:
<?php require 'path.php'; $filename = 'foo.txt'; $destination = new file\path($filename); $destination->set_temp_dir(); rename($filename, $destination); ?>
Example 3: to move a file to the current directory:
<?php require 'path.php';
$filename = new file\path('/var/www/foo.txt'); if ($filename->exists()) { $destination = new file\path($filename); $destination->set_current_dir(); rename($filename, $destination); } ?>
In order to remove part of the pathname, e.g. file extension or directory, simply assign NULL to that part:
<?php require 'path.php';
$filename = new file\path('/var/www/foo.txt'); $filename->dirname = $filename->extension = NULL; echo "$filename\n"; // outputs "foo\n" ?>
You can also build a pathname from scratch like this:
<?php require 'path.php';
$filename = new file\path; $filename->basename = 'foo.txt'; $filename->dir = '/var/www'; echo "$filename\n"; // outputs "/var/www/foo.txt" ?>
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Lic. | Licence text | ||
![]() |
Class | Class demonstrating use of file\path | ||
![]() |
Class | file\path class source | ||
![]() ![]() |
Data | Configuration for phpDocumentor | ||
![]() ![]() |
Doc. | Documentation text |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.