So... I've worked on a new function for ElfData.
Another file processing function.
ElfData.FileListing
This one, will list the children of a directory. It is properly POSIX
compliant. It uses Unix's opendir, not any silly functions like
FolderItem.Child which don't necessarily do the right thing with Unix
paths.
So for example, this code:
dim e as ElfData = "/usr"
msgbox e.FileListing
This gives a bunch of stuff on my Mac, including:
bin
include
lib
libexec
local
sbin
share
standalone
X11
X11R6
Nice eh? The nice thing about this, is you can combine this with
ElfDataFields, via ElfData.Lines. Another function I probably made
around a year ago but few people know about.
So for example, this simple code:
Protected Sub ProcessFile(path as ElfData)
dim e as ElfData = path.FileListing( 10, true ) // THE NEW FUNCTION
IS HERE!!!
if e <> nil then // it's a folder
dim fi as ElfDataFields = e.Lines
While fi.MoveNext
ProcessFile fi
wend
Return
end if
dim data as ElfData = path.FileData
if data = nil then Return
if data.IsASCII then
stdout.Write "ASCII"
elseif data.Verify = 0 then
stdout.Write "UTF-8"
else
stdout.Write "Latin-1"
end if
stdout.Write chrb(9)
stdout.WriteLine path
End Sub
Function Run(args() as String) As Integer
dim fi as ElfDataFields = args( 1 ).ElfData.Lines
While fi.MoveNext
ProcessFile fi
wend
End Function
OK... that basically, is all the RB code you need, for a Unix app,
that will check all the files in a directory, to see if those files
are UTF-8, not UTF-8 (it assumes anything that isn't valid UTF-8 is
Latin-1), or just plain old ASCII :)
And it works over the shell :D So now you got a tool to manage your
webserver, to check for which files are UTF-8 or not. This comes in
handy when you got multiple web developers and not all of them are
UTF-8 compliant ;)
And all in about 20 lines of ElfData code. Nice eh?
Anyhow... all of this uses some little known new functions of mine.
And by "new"... that includes stuff I made around a year or so ago,
but few people got in on.
New functions including:
ElfData.FileData as ElfData (Get and set!)
ElfData.Lines as ElfDataFields
ElfData.FileListing
ElfData.FastString (allows writing to a file)
ElfData.ElfDataFields (allows streaming a file in, very fast)
and many others... all using Unix functions. And because they are
using Unix functions "open", "read", and "write"... and no funny silly
stuff around them, like RB does, that kind of cripples their
"Unixness"... you can do cool stuff like this:
dim f as ElfDataFile = "/dev/random"
msgbox f.Data(16).Hex
this will return different hex data each time. Fully "unixish" :)
Anyhow, because of all these "new" functions. I think it's about time
I created a page about ElfData's file handling functions. So all the
file handling functions (scattered all over my plugin in various
classes!!!) are listed. So you can know what ElfData is capable of.