Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Walking members of an OLE/ActiveX collection
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 15th February 04:06
doug l.
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection



How can I walk the members of an OLE/ActiveX collection (represented by an
OLEObject) without using a "do ... over ..." statement in Rexx? The
collection is supposed to have two methods, count() and item(*), and count()
works as expected, but trying to get item(1) fails. The do-over statement
is supposed to work on collections which support the makearray() method, but
the OLEObject does not support makearray(), so how does do-over itself
access the collection.

My motivation is to print a list of all the files and folders of a drive
efficiently with files and folders _intermixed_ alphabetically. The
following code is a single directory-level version of the best I've been
able to do so far, but it prints the names of all files before printing the
names of any directory.

fso = .OLEObject~new('Scripting.FileSystemObject')
root_folder = fso~getFolder('\')

files = root_folder~files
do file1 over files
say file1~path
end

folders = root_folder~subFolders
do folder1 over folders
say folder1~path
end

I'd like to replace the two loops above with one which is something like the
following sketch:

files = root_folder~files
folders = root_folder~subFolders
file1 = files~first
folder1 = folders~first

do while ...more...
if file1~path < folder1~path then do -- (plus
eof-handling code)
say file1~path
file1 = files~next
end
else do
say folder1~path
folder1 = folders~next
end
end

For efficiency considerations when printing an entire drive, I don't want to
create "normal" Rexx collections as intermediaries. I'm using Object Rexx
on Windows/XP.


Regards,
Doug Lorch
  Reply With Quote


  sponsored links


2 15th February 04:06
lee peedin
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection



Doug

This link may explain why the method item() does not work.
http://listserv.activestate.com/pipermail/perl-win32-users/2002-August/022790.html


As much as I like the FilsSystemObject and ActiveX/OLE, I believe it's
a bit of overkill (if I understand what you're wanting to do).

Try this bit of code and see if it is what you're wanting.

/* testsft.rex */

say 'Be Patient - Got To Collect A Lot of Files'
rv = SysFileTree('\',allfiles.,'sb')
do i = 1 to allfiles.0
len = length(allfiles.i)
say substr(allfiles.i,38,len-37)
end
say 'Total Number of Entries:' allfiles.0

Lee Peedin
VP RexxLA
  Reply With Quote
3 15th February 04:06
ptjm
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


% How can I walk the members of an OLE/ActiveX collection (represented by an
% OLEObject) without using a "do ... over ..." statement in Rexx? The
% collection is supposed to have two methods, count() and item(*), and count()
% works as expected, but trying to get item(1) fails.

Some objects take either a string or a number as arguments to item(). If
that's the case here, Rexx is likely to fall down about because everything's
a string. You need a way to coerce object rexx into passing a binary integer
to the method (I can't say how as I don't use object Rexx).
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com
  Reply With Quote
4 15th February 04:06
lee peedin
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


"item" is a method of the "subfolders" object - subfolders~item() -
however, ~item() takes a *key*, not an index.

Here is a bit of Perl (ugh) that demonstates this

foreach $keyObj (in $folder->SubFolders) {
my $subfolder = $folder->SubFolders->Item($keyObj->{Name});
.....

For the item method to be used, you must be "redundant" in the key to
pass it. So it really has no real value - at least that's the opinion
I've been able to glean from several posting concerning
subfolders~item()

I think the OP was attempting to retrieve an individual "item" by an
index number in order to do an alpha sort; however, simply using the
Rexx bif SysFileTree with the option 'b' (to retrieve both directories
and files) and the option 's' (to include recursive sub-folders) will
accomplish the same thing - at least on my system they come out in
alpha order.

Maybe it's "clear as mud" now :-).

Lee
  Reply With Quote
5 15th February 04:06
doug l.
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


Thanks for the response, but the reason I want to use OLEObject is that it
can retrieve the time a file was last accessed whereas SysFileTree only
returns the time a file was last modified (and, besides, it's something new
to learn).

Your link to the explanation why item(1) doesn't work is what I'd expected,
which leaves me wondering how Rexx's "do ... over ..." statement was
implemented. I'd like to get access to whatever API it uses. Another use
for such an API is to allow me to write a subroutine which can return one
file per call, which would be impossible using "do ... over ..." without
either initially gathering all files into a more accessible collection, or
using multithreading (ugh).

By the way, I did some timing runs a while ago, and the SysFileTree approach
is faster than OLEObject when accessing about 100 files, but it is 3+ times
slower when scanning all files on a 30 gig drive. My guess is that is
because doing SysFileTree on the entire drive causes over 100,000 stem
variables to be created. Doing SysFileTree directory by directory is
faster, but I don't know how much.

-- Doug Lorch
  Reply With Quote
6 15th February 04:06
gert van der kooij
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


In article <gjJcb.15719$vj2.1921@fed1read06>, No_Spam@hotmail.com
says...


You can use SysGetFileDateTime to get that time.
  Reply With Quote
7 15th February 04:06
mark yudkin
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


I am not privy to the OO-REXX internals, so the following may be way out,
but the chances are good it's correct, especially since I can confirm from
the collection implementer's side that the relevant methods are called.

by calling [Clone,] Reset, Next [and Skip]. Most specific objects derive
from this, to implement iterators. The enumerator itself (IEnumVariant
dispatch handle, actually its IUnknown interface pointer) is returned by the
hidden _NewEnum property (the initial _ on the name means "hidden", it has
the DISPID -4). High level scripting languages hide this mess behind a
statement such as REXX's "do over".

REXX knows whether it's dealing with an ActiveX object or not, thus it can
use the correct access path.

Further details on ActiveX can be found in the section on Component
Development in the Microsoft Platform SDK; its available from the MS web site (http://msdn.microsoft.com/library/default.asp).
"Doug L." <No_Spam@hotmail.com> wrote in message news:gjJcb.15719$vj2.1921@fed1read06...
  Reply With Quote
8 15th February 04:06
ptjm
External User
 
Posts: 1
Default Walking members of an OLE/ActiveX collection


% "item" is a method of the "subfolders" object - subfolders~item() -
% however, ~item() takes a *key*, not an index.

I wouldn't take some perl programmer's word for this, especially
since *key* is meaningless in the context of OLE types.

% Here is a bit of Perl (ugh) that demonstates this %
% foreach $keyObj (in $folder->SubFolders) {
% my $subfolder = $folder->SubFolders->Item($keyObj->{Name});

What this is showing is that Item _can_ take a *string*. The fact
that the string is derived from an object called key is not
especially useful to know.

% I think the OP was attempting to retrieve an individual "item" by an
% index number in order to do an alpha sort; however, simply using the

This will normally work, but, as I said, in cases where Item accepts
both a string and a number, you have to tell the automation interface
that you want to pass a number. There's a way of doing this, for instance,
with w32Funcs's automation interface. Since object Rexx's automation
support is generally much better, I wouldn't be surprised to find there's
a way to do it with object Rexx, too.

I agree that using SysFileTree is likely to be simpler.
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666