parsing - Find File based on partial file name and move file elsewhere in vbs -



parsing - Find File based on partial file name and move file elsewhere in vbs -

i'm looking write vbs script following. - there mapping file contains identifier followed directory name (e.g. 123456-documents). - each line in mapping file, there document begins identifier need move elsewhere (e.g. 123456_otherstuff_dec 12.xls). - need parse total filename , take middle string (otherstuff) determine sub directory goes into.

so in above example, file "123456_otherstuff_dec 12.xls" should end in directory c:.../current/documents/otherstuff/123456_otherstuff_dec 12.xls.

i'm new vbs, know bit of java have been able create start on this. have far:

set objfso = createobject("scripting.filesystemobject") set objfile = objfso.opentextfile("c:\documents , settings\w133960\desktop\test1\text1.txt", forreading) const forreading = 1 dim arrfilelines() = 0 until objfile.atendofstream redim preserve arrfilelines(i) arrfilelines(i) = objfile.readline = + 1 loop objfile.close each strline in arrfilelines wscript.echo strline myarray = split(strline, "-", -1, 1) wscript.echo myarray(0) wscript.echo myarray(1) next

this goes through mapping file , parse identifer me. next part searching file origin identifier, parse it's filename , move relevant directory based on that. add together loop within current loop, parse filename , move file within loop - worried efficieny of there few hundred files move. can advise on cleanest , efficient way of doing this? help much appreciated.

a plan:

a first loop extract ids (and folder names) mapping file dictionary (key = id, value = folder name (possibly)) [never duplicate lines collection in file array in memory, if don't need access item process item j (i <>j)] a sec loop on files in (one , only?) source directory. split ofile.name on correct! separator "_", not "-". if id found in dictionary, utilize parts build (filesystemobject.buildpath()) new/target file spec. check (filesystemobject.fileexists()) whether targext exists, if not, ofile.move

file parsing scripting vbscript

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -