scripting - How to move files from one directory to another? -


i have requirement , i'm not sure how go it. need write vbscript files in specified directory. if file found need move a different directory(archive).

for example, have file z001_130711.txt in directory c:\transfer, first 4 characters of filename same change last 6 characters can see date of when file created/run.

before move file have other things , came vbscript code already.

after i'm done need move c:\transfer\archive. i'm stuck , don't know how it.

any appreciated.

this should of way. you'll need figure out correct replacement phrase "if ucase(right(objfile.name, 4)) = ".vbp" then"

also destination files have ".bak" appended. you'll need remove that.

the rational placing list of files in dictionary escapes me @ moment. think had process failing enough needed able list of files handled vs didn't.

option explicit  dim dicfiles  set dicfiles = createobject("scripting.dictionary")  private sub addfile(objfile)   if dicfiles nothing     set dicfiles = createobject("scripting.dictionary")   end if   if not dicfiles.exists(objfile.path)     dicfiles.add objfile.path, "false"   end if end sub    dim strrootpath 'as string   dim objfso 'as new filesystemobject   dim objfile 'as file   dim 'as integer   dim imax 'as integer    strrootpath = "c:\transfer"   dim objfolder' folder   set objfso = createobject("scripting.filesystemobject")   set objfolder = objfso.getfolder(strrootpath)    'msgbox "" & objfolder.files.count & " files in folder " & objfolder.path   each objfile in objfolder.files     'msgbox "filespec: " & objfile.name     if ucase(right(objfile.name, 4)) = ".vbp"        'msgbox "adding file " & objfile.name       addfile objfile     end if   next    dim arrfiles '() variant   arrfiles = dicfiles.keys    'msgbox "ubound(arrfiles)=" & ubound(arrfiles)    dim fsin 'as string   dim fsout 'as string   dim strfilespec 'as string   = 0 ubound(arrfiles)     set objfile = objfso.getfile(arrfiles(i))     strfilespec = arrfiles(i)     fsout = strfilespec & ".bak"     if objfso.fileexists(fsout)       objfso.deletefile fsout, true  'true = force     end if      fsin = strfilespec     objfso.movefile fsin, fsout    next    set objfso = nothing 

Comments