Associators problem

G

Guest

My below script doesn't work as expected. No error message and nothing
happens. What can i do to fix this problem.?
I really want to list all files in current folder and its subfolders
thank you

============beginning===========
'This script lists all files in current folder and its subfolders

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FileList = objWMIService.ExecQuery("ASSOCIATORS OF
{Win32_Directory.Name='c:\apache2'}" & " Where AssocClass =
Win32_Subdirectory ResultRole = PartComponent" & " ResultClass = CIM_DataFile
")

For Each objFile In FileList

wscript.echo(objFile.Name)

Next
=========ending==================
 
T

Torgeir Bakken \(MVP\)

CuriousMe said:
My below script doesn't work as expected. No error message and nothing
happens. What can i do to fix this problem.?
I really want to list all files in current folder and its subfolders
thank you

============beginning===========
'This script lists all files in current folder and its subfolders

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FileList = objWMIService.ExecQuery("ASSOCIATORS OF
{Win32_Directory.Name='c:\apache2'}" & " Where AssocClass =
Win32_Subdirectory ResultRole = PartComponent" & " ResultClass = CIM_DataFile
")

For Each objFile In FileList

wscript.echo(objFile.Name)

Next
=========ending==================
Hi,

You need to use a recursive Sub:

http://groups.google.co.uk/group/mi...cript/msg/c95d370dc251e4c1?dmode=source&hl=en
 
G

Guest

I wrote a similar script in VBScript and it works but when I wrote it in
JScript , it doesn't work. I mean there is no error message at all

what do i need to do to fix this problem.?

thanks.
===========beginning================

var strComputer = ".";

var objWMIService = GetObject("winmgmts:\\\\" + strComputer +
"\\root\\cimv2");

var dir="c:\\php5";

EnumAll(dir);

function EnumAll(fldr) {

var FileList = objWMIService.ExecQuery("ASSOCIATORS OF
{Win32_Directory.Name='fldr'}" + " Where ResultClass = CIM_DataFile ");

var fl=new Enumerator(FileList);

for(;!fl.atEnd();fl.moveNext())
{ var objFile=fl.item();

WScript.echo("File: "+objFile.Name);

}

var Folders=objWMIService.ExecQuery("ASSOCIATORS of
{Win32_Directory.Name='fldr'}" + " where AssocClass = Win32_Subfldrectory
ResultRole = PartComponent");

var fd=new Enumerator(Folders);
for(;!fd.atEnd();fd.moveNext())
{
WScript.echo("\nFOLDER: "+folder.Name+"\n");

EnumAll(folder.Name); //recursion. Go through everything

}
}

=============ending================
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top