| 1 |
NAME |
| 2 |
SHARYANTO::File::Util - File-related utilities |
| 3 |
|
| 4 |
VERSION |
| 5 |
version 0.56 |
| 6 |
|
| 7 |
SYNOPSIS |
| 8 |
use SHARYANTO::File::Util qw(file_exists l_abs_path dir_empty); |
| 9 |
|
| 10 |
print "file exists" if file_exists("/path/to/file/or/dir"); |
| 11 |
print "absolute path = ", l_abs_path("foo"); |
| 12 |
print "dir exists and is empty" if dir_empty("/path/to/dir"); |
| 13 |
|
| 14 |
DESCRIPTION |
| 15 |
FUNCTIONS |
| 16 |
None are exported by default, but they are exportable. |
| 17 |
|
| 18 |
file_exists($path) => BOOL |
| 19 |
This routine is just like the -e test, except that it assume symlinks |
| 20 |
with non-existent target as existing. If "sym" is a symlink to a |
| 21 |
non-existing target: |
| 22 |
|
| 23 |
-e "sym" # false, Perl performs stat() which follows symlink |
| 24 |
|
| 25 |
but: |
| 26 |
|
| 27 |
-l "sym" # true, Perl performs lstat() |
| 28 |
-e _ # false |
| 29 |
|
| 30 |
This function performs the following test: |
| 31 |
|
| 32 |
!(-l "sym") && (-e _) || (-l _) |
| 33 |
|
| 34 |
l_abs_path($path) => STR |
| 35 |
Just like Cwd::abs_path(), except that it will not follow symlink if |
| 36 |
$path is symlink (but it will follow symlinks for the parent paths). |
| 37 |
|
| 38 |
Example: |
| 39 |
|
| 40 |
use Cwd qw(getcwd abs_path); |
| 41 |
|
| 42 |
say getcwd(); # /home/steven |
| 43 |
# s is a symlink to /tmp/foo |
| 44 |
say abs_path("s"); # /tmp/foo |
| 45 |
say l_abs_path("s"); # /home/steven/s |
| 46 |
# s2 is a symlink to /tmp |
| 47 |
say abs_path("s2/foo"); # /tmp/foo |
| 48 |
say l_abs_path("s2/foo"); # /tmp/foo |
| 49 |
|
| 50 |
Mnemonic: l_abs_path -> abs_path is analogous to lstat -> stat. |
| 51 |
|
| 52 |
Note: currently uses hardcoded "/" as path separator. |
| 53 |
|
| 54 |
dir_empty($dir) => BOOL |
| 55 |
Will return true if $dir exists and is empty. |
| 56 |
|
| 57 |
None are exported by default, but they are exportable. |
| 58 |
|
| 59 |
FAQ |
| 60 |
Where is file_empty()? |
| 61 |
For checking if some path exists, is a regular file, and is empty |
| 62 |
(content is zero-length), you can simply use the "-z" filetest operator. |
| 63 |
|
| 64 |
AUTHOR |
| 65 |
Steven Haryanto <[email protected]> |
| 66 |
|
| 67 |
COPYRIGHT AND LICENSE |
| 68 |
This software is copyright (c) 2013 by Steven Haryanto. |
| 69 |
|
| 70 |
This is free software; you can redistribute it and/or modify it under |
| 71 |
the same terms as the Perl 5 programming language system itself. |
| 72 |
|