]>
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: 2004-02-06
21 use base
qw(Exporter);
31 # Collect the files and directories in a directory
35 # Return: Hash reference: dirs => directories
43 return unless(-d
$dir);
45 # Get all the entries in the directory
47 opendir(DIR
,$dir) or return;
48 my @entries = readdir(DIR
);
49 closedir(DIR
) or return;
53 @entries = sort(@entries);
58 foreach my $entry(@entries)
60 next if($entry eq "." || $entry eq "..");
62 if(-d
$dir."/".$entry)
72 return {dirs
=> \
@dirs, files
=> \
@files};
79 # Params: File to create
81 # Return: true on success;
82 # false on error or if the file already exists
91 open(FILE
,">$file") or return;
92 close(FILE
) or return;
99 # Read out a file completely
103 # Return: Contents of the file (Scalar Reference)
110 open(FILE
,"<$file") or return;
111 read(FILE
, my $content, -s
$file);
112 close(FILE
) or return;
122 # 2. File content as Scalar Reference
124 # Return: Status code (Boolean)
128 my ($file,$content) = @_;
131 open(FILE
,">$file") or return;
132 print FILE
$$content or do { close(FILE
); return };
133 close(FILE
) or return;
140 # Remove a file from the list of files in use
142 # Params: 1. File::UseList object
149 my ($uselist,$file) = @_;
151 $uselist->remove_file($file);
157 # it's true, baby ;-)
patrick-canterino.de