csv - VBScript to loop through all files in a folder -
i have code carry out process on single file, alter script loops through files in directory "h:\letter display\letters" file type ".ltr" , saves them all:
const forreading = 1 const forwriting = 2 set objfso = createobject("scripting.filesystemobject") set objfile = objfso.opentextfile("h:\letter display\letters\ltrprt__00000008720000000001ni-k-rmnd.ltr", forreading) str1000 = "1000" str1100 = "1100" str1200 = "1200" str9990 = "9990" arrcommas1 = array(14,31,41,59,70,81,101,111,124,138) arrcommas2 = array(14,31,41,55,79,144,209,274,409,563,589,608,623) arrcommas3 = array (14,32,41,73,83,97,106,156,167,184,188,195,207,260,273,332,368,431,461,472,593,617,666,772,810,834,848,894,898) arrcommas4 = array(14,31,41) until objfile.atendofstream strline = objfile.readline if left(strline, 4) = str1000 intlength = len(strline) each strcomma in arrcommas1 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str1100 intlength = len(strline) each strcomma in arrcommas2 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str1200 intlength = len(strline) each strcomma in arrcommas3 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str9990 intlength = len(strline) each strcomma in arrcommas4 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if strtext = strtext & strline & vbcrlf loop objfile.close set objfile = objfso.opentextfile("h:\letter display\letters\ltrprt__00000008720000000001ni-k-rmnd.ltr", forwriting) objfile.write strtext objfile.close
any appreciated!
thanks
maybe clear things up. (or confuse more, )
const forreading = 1 const forwriting = 2 sfolder = "h:\letter display\letters\" set ofso = createobject("scripting.filesystemobject") each ofile in ofso.getfolder(sfolder).files if ucase(ofso.getextensionname(ofile.name)) = "ltr" processfiles ofso, ofile end if next set ofso = nothing sub processfiles(fso, file) set ofile2 = fso.opentextfile(file.path, forreading) str1000 = "1000" str1100 = "1100" str1200 = "1200" str9990 = "9990" arrcommas1 = array(14,31,41,59,70,81,101,111,124,138) arrcommas2 = array(14,31,41,55,79,144,209,274,409,563,589,608,623) arrcommas3 = array (14,32,41,73,83,97,106,156,167,184,188,195,207,260,273,332,368,431,461,472,593,617,666,772,810,834,848,894,898) arrcommas4 = array(14,31,41) until ofile2.atendofstream strline = ofile2.readline if left(strline, 4) = str1000 intlength = len(strline) each strcomma in arrcommas1 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str1100 intlength = len(strline) each strcomma in arrcommas2 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str1200 intlength = len(strline) each strcomma in arrcommas3 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if if left(strline, 4) = str9990 intlength = len(strline) each strcomma in arrcommas4 strline = left(strline, strcomma - 1) + "," _ + mid(strline, strcomma, intlength) next end if strtext = strtext & strline & vbcrlf loop sfile = file.path ofile2.close set ofile2 = nothing set file = fso.opentextfile(sfile , forwriting) file.write strtext file.close set file = nothing end sub
Comments
Post a Comment