vbscript - VB Script Error - Worked before but now not confusingly -


i getting error

error getting

the vb file reads col1 , finds matching image name in directory , renames file col2 produces report show images haven't been renamed , placed ones have in folder called rename

i have attached code can see

strdocmap = "c:\img\docmap.xlsx" strinputfolder = "c:\img\" stroutputfolder = "c:\img\renamed\" strlogfile = "c:\img\renaminglog.txt"  strpattern = "\d{5}"  set regexpression = new regexp regexpression .global = true .ignorecase = true .pattern = strpattern end set objexcel = createobject("excel.application") objexcel.visible = true const xlup = -4162 const xlformulas = -4123 const xlpart = 2 const xlbyrows = 1 const xlnext = 1 set objwb = objexcel.workbooks.open(strdocmap, false, true) set objsheet = objwb.sheets(1) set objfso = createobject("scripting.filesystemobject") if right(strinputfolder, 1) <> "\" strinputfolder = strinputfolder & "\" if right(stroutputfolder, 1) <> "\" stroutputfolder = stroutputfolder & "\"  if objfso.folderexists(stroutputfolder) = false objfso.createfolder stroutputfolder set objlog = objfso.createtextfile(strlogfile, true) objlog.writeline "script started " & objlog.writeline "enumerating files in folder: " & strinputfolder objlog.writeline "renaming files folder: " & stroutputfolder objlog.writeline string(80, "=")  each objfile in objfso.getfolder(strinputfolder).files set colmatches = regexpression.execute(objfile.name) if colmatches.count > 0     if colmatches.count = 1         each objmatch in colmatches             stroldnum = objmatch.value             set objcell = objsheet.cells.find(stroldnum,         objsheet.range("a1"), xlformulas, xlpart, xlbyrows, xlnext, false, false)             if not objcell nothing                 strnewnum = objcell.offset(0, 1).value                 if strnewnum <> ""                     strnewpath = stroutputfolder & strnewnum & "." & objfso.getextensionname(objfile.path)                     ' check if file exists without appended letter                     blnvalid = true                     if objfso.fileexists(strnewpath) = true                         blnvalid = false                         ' start @ "a"                         intletter = 97                         strnewpath = stroutputfolder & strnewnum & chr(intletter) & "." & objfso.getextensionname(objfile.path)                         while objfso.fileexists(strnewpath) = true                             intletter = intletter + 1                             strnewpath = stroutputfolder & strnewnum & chr(intletter) & "." & objfso.getextensionname(objfile.path)                             if intletter > 122 exit                         loop                         if intletter <= 122 blnvalid = true                     end if                     if blnvalid = true                         objlog.writeline "renaming " & objfile.name & " " & mid(strnewpath, instrrev(strnewpath, "\") + 1)                         objfso.movefile objfile.path, strnewpath                     else                         objlog.writeline "unable rename " & objfile.name & ". letters exhausted."                     end if                 end if             end if         next     else         objlog.writeline objfile.name & " contains " & colmatches.count & " matches. manual adjustment required."     end if end if next objlog.writeline string(80, "=") objlog.writeline "script finished " & objwb.close false objexcel.quit  objlog.close msgbox "done" 

thanks

jack

if line 68

objlog.writeline objfile.name & " contains " & colmatches.count & " matches. manual adjustment required." 

is culprit, argue:

  1. the objects objlog, objfile, , colmatches used before - acquittal
  2. the methods .writeline, .name, , .count - acquittal
  3. concatenation (&) should work on string literals , not null/empty/nothing elements - acquittal
  4. by elimination: objfile.name contains funny letter (not convertable 'ascii'). easy check: replace "objfile.name" string literal.

evidence

  dim s   each s in array(empty, null, chrw(1234))     on error resume next      gofs.createtextfile("tmp.txt", true).writeline s      wscript.echo err.description     on error goto 0   next 

output:

====================================  type mismatch invalid procedure call or argument ==================================== 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -