List Files in all folders and subfolders using WMI

Discussion in 'Scripting' started by LSmith, Apr 10, 2006.

  1. LSmith

    LSmith Guest

    In pgm A using Set colItems = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Directory where Drive = '" & sDrive & "' and Path
    = '" & sDirName & "'", "WQL", wbemFlagReturnImmediately +
    wbemFlagForwardOnly) as part of a recursive subroutine, I am able to recurse
    thru all dirs and subdirs.

    In pgm B using Set colItemsFile = objWMIService.ExecQuery _
    ("SELECT * FROM CIMDataFile where Drive = '" & sDrive & "' and Path = '"
    & sDirNameForFiles & "'", "WQL", wbemFlagReturnImmediately +
    wbemFlagForwardOnly), I am able to show all files.

    I want to be able to show all files for each dir. When I combine the two:
    set colItems ...
    For Each objItem in colItems
    Set colItemsFile...
    error "x'80001010' specified class is invalid" occurs.

    How to I make this work?
    How to trap this error - 'If Err <> 0 then' and 'If Err.Number then' with
    On Error Resume Next don't trap it.
    LSmith, Apr 10, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.