]>
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-08-05
21 use base qw(Exporter);
32 # Change the group of files or directories
34 # Params: 1. Group name
37 # Return: Number of files group successfully changed
42 my ($group,@files) = @_;
43 my $gid = ($group !~ /^\d+$/) ?
getgrnam($group) : $group;
46 return chown(-1,$gid,@files);
51 # Collect the files and directories in a directory
55 # Return: Hash reference: dirs => directories
63 return unless(-d
$dir);
65 # Get all the entries in the directory
67 opendir(DIR
,$dir) or return;
68 my @entries = readdir(DIR
);
69 closedir(DIR
) or return;
73 @entries = sort {uc($a) cmp uc($b)} @entries;
78 foreach my $entry(@entries)
80 next if($entry eq "." || $entry eq "..");
82 if(-d
$dir."/".$entry)
92 return {dirs
=> \
@dirs, files
=> \
@files};
99 # Params: File to create
101 # Return: true on success;
102 # false on error or if the file already exists
111 sysopen(FILE
,$file,O_RDONLY
| O_CREAT
) or return;
112 close(FILE
) or return;
119 # Read out a file completely
123 # Return: Contents of the file (Scalar Reference)
130 sysopen(FILE
,$file,O_RDONLY
) or return;
131 read(FILE
, my $content, -s
$file);
132 close(FILE
) or return;
142 # 2. File content as Scalar Reference
144 # Return: Status code (Boolean)
148 my ($file,$content) = @_;
151 sysopen(FILE
,$file,O_WRONLY
| O_CREAT
| O_TRUNC
) or return;
152 print FILE
$$content or do { close(FILE
); return };
153 close(FILE
) or return;
160 # Remove a file from the list of files in use
162 # Params: 1. File::UseList object
169 my ($uselist,$file) = @_;
171 $uselist->remove_file($file);
177 # it's true, baby ;-)
patrick-canterino.de