csv - WMI Query returning null collection when querying Win32_Directory -


i'm trying use vbscript select csv's in specific folder , concatenate them one. adding of csv's collection using execquery on win32_directory, specifying path , extension properties. have 5 csv's in folder test. collection returned null.

here's code:

strcomputer = "." set wshshell = wscript.createobject( "wscript.shell" ) set objwmiservice = getobject("winmgmts:" _    & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")  'options createtextfile booloverwrite = true boolunicode = true  'options opentextfile constforreading = 1 constforwriting = 2 constforappending = 8 boolcreate = false consttristate = -1  strpath = "c:\users\adam\documents\test\temp.csv" strdrivepath = "c:\users\adam\documents\test"  'creates object reference files in relevant folder. set objfso = createobject ("scripting.filesystemobject")  'creates new csv write others' contents to. set objnew = objfso.createtextfile(strpath,booloverwrite,boolunicode)  set colcsv = objwmiservice.execquery _  ("select * win32_directory path = strdrivepath , extension = 'csv'")  'concatenates contents of csvs each objcsv in colcsv  set objtemp = objfso.opentextfile(objcsv.path & objcsv.filename & objcsv.extension,constforreading,boolcreate,consttristate)  set strline = objtemp.readline  objnew.write strline   next 

i unsure of whether way i've specified path opentextfile going work or not. main concern right getting query return files want.

thanks help!

you've got few issues here.

  1. if want select files, use cim_datafile class. win32_directory for, guessed it, directories.

  2. backslashes in path property must escaped (\\).

  3. strdrivepath variable you're using literally in wmi query.

  4. is intention run script on remote machine? if not, why not use filesystemobject methods? have fso object created.

here similar question answered in past showing how can use filesystemobject or wmi query find files matching specification.

in situation, query might this:

strfilespec = "c:\\users\\adam\\documents\\test\\%.csv"  set colcsv = objwmiservice.execquery _  ("select * cim_datafile name '" & strfilespec & "'") 

but query run faster (often noticeably) if specify values drive , path in statement. see linked post example.

edit: realized op of question linked well!


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -