Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cycle through folder extracting info from text files

Status
Not open for further replies.

SQLScholar

Programmer
Aug 21, 2002
2,127
GB
Hey all,

I have the below code.

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

strComputer = "."

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

Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\audit\software'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile In colFileList
    strName = objFile.FileName 
    strName = Replace(strName, "_", " ")
    'Wscript.Echo strName

    Set objFile = objFSO.OpenTextFile(objFile.Name, ForReading)

    Do Until objFile.AtEndOfStream
        strLine = objFile.ReadLine
		IF instr(strline,"DisplayName	REG_SZ") then
			StrNewFile =  strLine & "," & strName & VBCR
		end if
    Loop
    objFile.close
Next

Set objFile = objFSO.OpenTextFile("C:\Audit\software_audit.txt", ForWriting)
objFile.Write StrNewFile 

objFile.Close

and i am getting an error on this line

Set objFile = objFSO.OpenTextFile("C:\Audit\software_audit.txt", ForWriting)
objFile.Write StrNewFile

saying

"Invalid procedure call or argument".

Any ideas?

I cant work out what i am doing wrong?

Many thanks

Daniel

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
ignore that .... just seen it.

Set objFile = objFSO.OpenTextFile("C:\Audit\software_audit.txt", ForWriting)

should be

Set objFile = objFSO.OpenTextFile("C:\Audit\software_audit.txt", 2)

Sorry!

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
...
For Each [!]objFile[/!] In colFileList
...
Set [!]objFile[/!] = objFSO.OpenTextFile(objFile.Name, 2)
...
Next

I'd use another object inside the loop.

Furthermore StrNewFile contains only the last line found.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top