]>
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: 09-26-2003
22 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 File
::Spec
->canonpath($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) = @_;
129 my $temp = $file.".temp";
132 open(FILE
,">",$temp) or return;
133 print FILE
$$content or do { close(FILE
); return };
134 close(FILE
) or return;
136 rename($temp,$file) or return;
141 # it's true, baby ;-)
patrick-canterino.de