Something like the following might do what you need. You could put it
in a file that you source before invoking the function, or just place
the file in the "init" folder in your custom directory, so it's always
available.
The function takes a file name pattern (e.g., 'Data\??' to match items
with two-character names). Directories matching the pattern are then
searched for ".xml" files, each of which is checked and a list of
those that couldn't be opened or failed the completeness check is
returned.
I've left the task of writing the resulting list to a file or to
standard output as an exercise, since I don't know how you intend to
invoke Editor to run this, or if you'll have something processing the
result. Check back if you get stuck on that part.
Caveat: I did test this, but then I reformatted, added comments and
tweaked a bit, so no guarantees. 😉
-Brandon 🙂
function check_directories(pat){ local dirs[], files[], doc, i, j =
0, s = ";
# Make a list of items matching "pat" that are directories
glob(pat, files); for (i in files) { if
(file_directory(files[i])) { dirs[j++] = files[i]; } }
# Search each directory for XML files and check each one for (i
in dirs) { glob(dirs[i] . '\*.xml', files); for (j in
files) { # 1024 = fail quietly if document type
can't be loaded # 512 = do not load a stylesheet
# 32 = suppress parser errors and warnings # 1 = open
read-only doc = doc_open(files[j], 1024+512+32+1);
if (doc < 0 || doc_incomplete(doc, 3)) { #
Document couldn't be opened or failed completeness check
s = s . files[j] . "\n"; } doc_close(doc);
} }
# Return list of files needing attention return s;}