5 pts.
 VB script to copy valid data to another file
I am new to Scripting (Vb).  I need to do the following thru VB script. Is this possible?

There are few VB scripts which is currently performing the file transfer function (transferring these files from the network drive to the application). Some times, this text file contain some junk data in the first few lines.Script which does the transfer will not transfer such files. I would like to know whether there is a way to delete this junk data and create a new file with a different extension in the same path which i could transfer later. Same path can have more than 1 file like this...

Data in the file looks something like this:

ÃRØ5ŠÂ� N¦ËÀ#=�³€¹“®i6(“ ¶L¦}¡Ï…#–üÕ��–Ì|/sÅ/¯—ؐ���Üäÿ�[ßïéü±ö§º8L…VE¼(·(o� 1     000007887728721798327407428397483978971098700000 970987943209989898989234324321432543265436 435432543623443234263252532342

I want to retrieve starting 00000 (the file can have only numbers in all the lines and nothing else). Right now, i am doing it manually. Copy it from 000007887 till the end of the file and then create a new file (since i know even that 1 and the spaces following that are junk). I would like some kind of script which could do this funcitonality...

 

 

 

 

  



Software/Hardware used:
VBSCRIPT
ASKED: September 17, 2009  5:59 PM
UPDATED: September 21, 2009  8:24 PM

Answer Wiki:
You might find some nuggets in this....... The ref to a bat file is just to make permissions easier change directory and the launch of this script is handled by a 3 line lat file which is not always necessary. '************************************************************************************************************************* 'Author: Mike Johnson Sept 2009 'Optimized for an Epicor Vantage ERP System 'Purpose to modify the Trading Partner value on an outbound invoice to be the TP related to the 'ShipTo' rather than the 'BillTo' 'Also to make the PONum and Date/Time part of the file name for archive purposes 'CAUTION THIS IS A LIVE SCRIPT THAT IS MOVING DATA. '************************************************************************************************************************* 'This script is launched by a 3 line bat file 'VantageTo810.bat' that facilitates system run script permissions '10'********************************************************************************************************************* Modify_Invoice_Flat_Files 'Calls a function '************************************************************************************************************************* FUNCTION Modify_Invoice_Flat_Files Dim objFldr, objFso, objFileIn, objFileOut Dim strFilePath, strFileIn, strFileOut, strLineIn, strLineOut, strFullPath, strSection, strElement Dim strFind, strReplaceWith, strTime, strStamp, strPO, strHajoca, strDest, strArchive Dim aryLine Dim intIndx '19 Const conReading = 1 strFilePath = "\Vantage-ServerEpicoredi_dataoutbound810" strDest = "\epicorevisionoutbound810Transfer" strArchive = "\Vantage-ServerEpicoredi_dataoutboundArchive_810" Set objFso = CreateObject("Scripting.FileSystemObject") Set objFldr = objFso.GetFolder(strFilePath) FOR EACH f in objFldr.files '27 strFileIn = objFso.GetFileName(f) IF InStr(strFileIn, "Result") = 0 THEN strFullPath = strFilePath & "" & strFileIn Set objFileIn = objFso.OpenTextFile(strFullPath, conReading) DO UNTIL objFileIn.AtEndOfStream strLineIn = objFileIn.ReadAll aryLine = Split(strLineIn, "~") For i = 0 to uBound(aryLine) IF i = 1171 THEN '38 strPO = uCase(Trim(cStr(aryLine(i)))) END IF IF i = 1183 AND uCase(Left(Trim(cStr(aryLine(i))), 6)) = "HAJOCA" THEN strHajoca = "T" END IF IF i = 1235 AND strHajoca = "T" THEN strFind = uCase(Trim(cStr(aryLine(i)))) IF Left(strFind, 3) <> "HAJ" THEN '49 MsgBox "Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1236" & VBCRLF _ & "Write down this error message and call IT." END IF END IF IF i = 1708 AND strHajoca = "T" THEN strReplaceWith = uCase(Trim(cStr(aryLine(i)))) IF Left(strReplaceWith, 3) <> "HAJ" THEN '58 MsgBox "Was expecting HAJMID, HAJMTN, HAJPAC or HAJFLA at element 1708" & VBCRLF _ & "Write down this error message and call IT." END IF END IF NEXT LOOP strTime=Replace(TIME(),":","-") strTime=Replace(strTime," ","") strStamp=MONTH(DATE)&"-"&DAY(DATE)&"-"&RIGHT(YEAR(DATE),2)&"_"&strTime strFileOut = "Result_" & strStamp & "_PO_" & strPO & ".txt" strDest = strDest & "" & strFileOut '70 strArchive = strArchive & "" & strFileOut Set objFileOut = objFso.CreateTextFile(strDest, True) IF strHajoca = "T" THEN objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith)) ELSE objFileOut.Write(strLineIn) END IF Set objFileOut = objFso.CreateTextFile(strArchive, True) IF strHajoca = "T" THEN '82 objFileOut.Write(Replace(strLineIn,strFind,strReplaceWith)) ELSE objFileOut.Write(strLineIn) END IF objFileIn.close objFso.DeleteFile strFullPath, force '90 END IF NEXT END FUNCTION '************************************************************************************************************** Set objFldr = nothing Set objFso = nothing Set objFileIn = nothing Set objFileOut = nothing '100 strFilePath="" strFileIn="" strFileOut="" strFullPath="" strLineIn="" strLineOut="" strSection="" strElement="" strFind="" strReplaceWith="" strDest = "" strArchive="" aryLine="" intIndx=""
Last Wiki Answer Submitted:  September 18, 2009  5:16 pm  by  mgj   320 pts.
All Answer Wiki Contributors:  mgj   320 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _