]>
git.p6c8.net - devedit.git/blob - modules/File/Access.pm
4 # Dev-Editor - Module File::Access
6 # Some simple routines for doing things with files
7 # with only one command
9 # Author: Patrick Canterino <patshaping@gmx.net>
10 # Last modified: 2003-11-04
21 use base
qw(Exporter);
30 # Collect the files and directories in a directory
34 # Return: Hash reference: dirs => directories
42 return unless(-d
$dir);
44 # Get all the entries in the directory
46 opendir(DIR
,$dir) or return;
47 my @entries = readdir(DIR
);
48 closedir(DIR
) or return;
52 @entries = sort(@entries);
57 foreach my $entry(@entries)
59 next if($entry eq "." || $entry eq "..");
61 if(-d
$dir."/".$entry)
71 return {dirs
=> \
@dirs, files
=> \
@files};
78 # Params: File to create
80 # Return: true on success;
81 # false on error or if the file already exists
90 open(FILE
,">",$file) or return;
91 close(FILE
) or return;
98 # Read out a file completely
102 # Return: Contents of the file (Scalar Reference)
109 open(FILE
,"<",$file) or return;
110 read(FILE
, my $content, -s
$file);
111 close(FILE
) or return;
121 # 2. File content as Scalar Reference
123 # Return: Status code (Boolean)
127 my ($file,$content) = @_;
130 open(FILE
,">",$file) or return;
131 print FILE
$$content or do { close(FILE
); return };
132 close(FILE
) or return;
137 # it's true, baby ;-)
patrick-canterino.de