]>
git.p6c8.net - devedit.git/blob - modules/File/Access.pm
6ab193ed3ae78d01d777b4a27df7c35fe66d1b12
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-10-26
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 {uc($a) cmp uc($b)} @entries;
58 foreach my $entry(@entries)
60 next if($entry eq "." || $entry eq "..");
62 if(-d
$dir."/".$entry)
72 return {dirs
=> \
@dirs, files
=> \
@files};
77 # Create a file, but only if it doesn't already exist
79 # (I wanted to use O_EXCL for this, but `perldoc -f sysopen`
80 # doesn't say that it is available on every system - so I
81 # created this workaround using O_RDONLY and O_CREAT)
83 # Params: File to create
85 # Return: true on success;
86 # false on error or if the file already exists
95 sysopen(FILE
,$file,O_RDONLY
| O_CREAT
) or return;
96 close(FILE
) or return;
103 # Read out a file completely
107 # Return: Contents of the file (Scalar Reference)
114 sysopen(FILE
,$file,O_RDONLY
) or return;
115 read(FILE
, my $content, -s
$file);
116 close(FILE
) or return;
126 # 2. File content as Scalar Reference
128 # Return: Status code (Boolean)
132 my ($file,$content) = @_;
135 sysopen(FILE
,$file,O_WRONLY
| O_CREAT
| O_TRUNC
) or return;
136 print FILE
$$content or do { close(FILE
); return };
137 close(FILE
) or return;
144 # Remove a file from the list of files in use
146 # Params: 1. File::UseList object
153 my ($uselist,$file) = @_;
155 $uselist->remove_file($file);
161 # it's true, baby ;-)
patrick-canterino.de