![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | vbscript equivalent of copy a+b c Hi, I've searched how to do it but I'm unable to find a sollution. I want to log something on the computer while executing a VBScript. No problem. I want to have that log at the end of the script copied to a central location. No problem. I want all logs for today in one file on the central location, problem. What I'm looking for is the VBS equivalent of the prompt command COPY A.TXT+B.TXT C.TXT where in the end the file C contains te content of A and B. How to I do that in VB script? My last commands so far are: Set objFile = FSO.GetFile(strTmpDirectory & strFile) objFile.Copy (strDestination & strFile) But this wil just copy the file and overwrite an existing file. There does not seem to be an objFile.Append (strDestination & strFile) So how do I do this? Bono Bloksma |
My System Specs![]() |
| | #2 (permalink) |
| | Re: vbscript equivalent of copy a+b c On Jul 29, 9:40*am, "Bonno Bloksma" <b.blok...@xxxxxx> wrote: Quote: > Hi, > > I've searched how to do it but I'm unable to find a sollution. > I want to log something on the computer while executing a VBScript. No > problem. > I want to have that log at the end of the script copied to a central > location. No problem. > I want all logs for today in one file on the central location, problem. > > What I'm looking for is the VBS equivalent of the prompt command > COPY A.TXT+B.TXT C.TXT > where in the end the file C contains te content of A and B. > > How to I do that in VB script? > My last commands so far are: > * Set objFile = FSO.GetFile(strTmpDirectory & strFile) > * objFile.Copy (strDestination & strFile) > But this wil just copy the file and overwrite an existing file. *There does > not seem to be an > * objFile.Append (strDestination & strFile) > So how do I do this? > > Bono Bloksma wrote this subroutine many, many years ago to do the job ... ' Appends file2 to end of file1 Sub AppendFile(sFileSpec1, sFileSpec2) dim fso set fso = CreateObject("Scripting.FileSystemObject") With .OpenTextFile(sFileSpec1, 8) .Write fso.OpentextFile(sFileSpec2, 1).ReadAll End With End sub To use this to add two files together, use CopyFile to copy file A to C then append B to C. For example, ... FSO.CopyFile strTmpDirectory & strFileA, strDestFolder & strFileC appendFile strDestFolder & strFileC, strTmpDirectory & strFileB This approach works fine for reasonably sized files, say less than tens of megabytes, though there is almost no memory limitation, since it is based on virtual (paging) memory, not strictly available RAM. Very large files are just slower to copy over. Of course the other way to do it is to just Run the command shell COPY statement from the script ... with createobject("wscript.shell") .run "%comspec% /c copy " & sFileSpecA & "+" & sFileSpecB _ & sFileSpecC, 0, true end with Tom Lavedas *********** |
My System Specs![]() |
| | #3 (permalink) |
| | Re: vbscript equivalent of copy a+b c On Jul 29, 10:32*am, Tom Lavedas <tglba...@xxxxxx> wrote: Quote: > On Jul 29, 9:40*am, "Bonno Bloksma" <b.blok...@xxxxxx> wrote: > > > Quote: > > Hi, Quote: > > I've searched how to do it but I'm unable to find a sollution. > > I want to log something on the computer while executing a VBScript. No > > problem. > > I want to have that log at the end of the script copied to a central > > location. No problem. > > I want all logs for today in one file on the central location, problem. Quote: > > What I'm looking for is the VBS equivalent of the prompt command > > COPY A.TXT+B.TXT C.TXT > > where in the end the file C contains te content of A and B. Quote: > > How to I do that in VB script? > > My last commands so far are: > > * Set objFile = FSO.GetFile(strTmpDirectory & strFile) > > * objFile.Copy (strDestination & strFile) > > But this wil just copy the file and overwrite an existing file. *There does > > not seem to be an > > * objFile.Append (strDestination & strFile) > > So how do I do this? Quote: > > Bono Bloksma > AFAIK, there is still no append method available to scripting. *I > wrote this subroutine many, many years ago to do the job ... > > ' Appends file2 to end of file1 > Sub AppendFile(sFileSpec1, sFileSpec2) > dim fso > * set fso = CreateObject("Scripting.FileSystemObject") > * With .OpenTextFile(sFileSpec1, 8) > * * .Write fso.OpentextFile(sFileSpec2, 1).ReadAll > * End With > End sub > > To use this to add two files together, use CopyFile to copy file A to > C then append B to C. *For example, ... > > *FSO.CopyFile strTmpDirectory & strFileA, strDestFolder & strFileC > *appendFile strDestFolder & strFileC, strTmpDirectory & strFileB > > This approach works fine for reasonably sized files, say less than > tens of megabytes, though there is almost no memory limitation, since > it is based on virtual (paging) memory, not strictly available RAM. > Very large files are just slower to copy over. > > Of course the other way to do it is to just Run the command shell COPY > statement from the script ... > > with createobject("wscript.shell") > * .run "%comspec% /c copy " & sFileSpecA & "+" & sFileSpecB _ > * & sFileSpecC, 0, true > end with > > Tom Lavedas > *********** that is ... .run "%comspec% /c copy " & sFileSpecA & "+" & sFileSpecB _ & sFileSpecC, 0, true should be .run "%comspec% /c copy " & sFileSpecA & "+" & sFileSpecB _ & " " & sFileSpecC, 0, true Tom Lavedas *********** |
My System Specs![]() |
| | #4 (permalink) |
| | Re: vbscript equivalent of copy a+b c Bonno Bloksma wrote: Quote: > How to I do that in VB script? > My last commands so far are: > Set objFile = FSO.GetFile(strTmpDirectory & strFile) > objFile.Copy (strDestination & strFile) > But this wil just copy the file and overwrite an existing file. There does > not seem to be an > objFile.Append (strDestination & strFile) > So how do I do this? > There is another alternative to FSO (at least for win98), that is the "copyhere" method of shell.application. There are a couple of side benefits. For one, copyhere is faster than fso. And for another, if the copy takes long enough (don't ask what "enough" means), copyhere will show a dialog and a progressbar. And finally, if the dialog does show, you will also see an "animation", which looks like papers flying through the air. <code> ' script to demo shell.application, jw 04Dec07 Option Explicit Dim oSHApp ' as object Dim sSrc, sDest ' as string Const FOF_SIMPLEPROGRESS = 256 '(&H100) Set oSHApp = CreateObject("Shell.Application") sSrc = "c:\windows\temp\*.*" sDest = "A:\" ' use ms Animated Copy Applet, showing names and progressbar... oSHApp.Namespace(sDest).CopyHere sSrc ' use ms Animated Copy Applet, showing progressbar (but no names)... ' oSHApp.Namespace(sDest).CopyHere sSrc, FOF_SIMPLEPROGRESS Set oSHApp = nothing ' clean up WScript.Quit </code> cheers, jw ____________________________________________________________ You got questions? WE GOT ANSWERS!!! ..(but, no guarantee the answers will be applicable to the questions) |
My System Specs![]() |
| | #5 (permalink) |
| | Re: vbscript equivalent of copy a+b c On Jul 29, 1:32*pm, mr_unreliable <kindlyReplyToNewsgr...@xxxxxx> wrote: Quote: > Bonno Bloksma wrote: Quote: > > How to I do that in VB script? > > My last commands so far are: > > * Set objFile = FSO.GetFile(strTmpDirectory & strFile) > > * objFile.Copy (strDestination & strFile) > > But this wil just copy the file and overwrite an existing file. *There does > > not seem to be an > > * objFile.Append (strDestination & strFile) > > So how do I do this? > hi Bono, > > There is another alternative to FSO (at least for win98), > that is the "copyhere" method of shell.application. > > There are a couple of side benefits. *For one, copyhere > is faster than fso. *And for another, if the copy takes > long enough (don't ask what "enough" means), copyhere > will show a dialog and a progressbar. *And finally, > if the dialog does show, you will also see an "animation", > which looks like papers flying through the air. > > <code> > ' script to demo shell.application, jw 04Dec07 > Option Explicit > Dim oSHApp *' as object > Dim sSrc, sDest *' as string > Const FOF_SIMPLEPROGRESS = 256 '(&H100) > > Set oSHApp = CreateObject("Shell.Application") > > * *sSrc = "c:\windows\temp\*.*" > * *sDest = "A:\" > > * *' use ms Animated Copy Applet, showing names and progressbar... > * *oSHApp.Namespace(sDest).CopyHere sSrc > > * *' use ms Animated Copy Applet, showing progressbar (but no names).... > * *' oSHApp.Namespace(sDest).CopyHere sSrc, FOF_SIMPLEPROGRESS > > Set oSHApp = nothing *' clean up > WScript.Quit > </code> > > cheers, jw > ____________________________________________________________ > > You got questions? *WE GOT ANSWERS!!! *..(but, no guarantee > * * the answers will be applicable to the questions) FILE? The documents insist that it copies "files to a folder", which is what your example seems to imply, as well. Tom Lavedas *********** |
My System Specs![]() |
| | #6 (permalink) |
| | Re: vbscript equivalent of copy a+b c Tom Lavedas wrote: Quote: > Are you sure this APPENDS the source files to a single destination > FILE? The documents insist that it copies "files to a folder", which > is what your example seems to imply, as well. > mea culpa, jw |
My System Specs![]() |
| | #7 (permalink) |
| | Re: vbscript equivalent of copy a+b c Tom Lavedas wrote: Quote: > AFAIK, there is still no append method available to scripting. I > wrote this subroutine many, many years ago to do the job ... > > ' Appends file2 to end of file1 > Sub AppendFile(sFileSpec1, sFileSpec2) > dim fso > set fso = CreateObject("Scripting.FileSystemObject") > With .OpenTextFile(sFileSpec1, 8) > .Write fso.OpentextFile(sFileSpec2, 1).ReadAll > End With > End sub > > To use this to add two files together, use CopyFile to copy file A to > C then append B to C. For example, ... > > FSO.CopyFile strTmpDirectory & strFileA, strDestFolder & strFileC > appendFile strDestFolder & strFileC, strTmpDirectory & strFileB > > This approach works fine for reasonably sized files, say less than > tens of megabytes, though there is almost no memory limitation, since > it is based on virtual (paging) memory, not strictly available RAM. > Very large files are just slower to copy over. > > Of course the other way to do it is to just Run the command shell COPY > statement from the script ... > > with createobject("wscript.shell") > .run "%comspec% /c copy " & sFileSpecA & "+" & sFileSpecB _ > & sFileSpecC, 0, true > end with method, use Read method and just specify a large enough chunk (x clusters perhaps). The following makes no attempt to verify either file exists or that the media is writable (I leave that open as an exercise). AppendFile sFileSpecB, sFileSpecC ' Appends srcfile to dstfile regardless of content type Function AppendFile(srcfile, dstfile) Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim fso, f1, f2, Msg Set fso = CreateObject("Scripting.FileSystemObject") remaining = fso.GetFile(srcfile).Size If remaining > 0 Then Set f1 = fso.OpenTextFile(srcfile, ForReading) Set f2 = fso.OpenTextFile(dstfile, ForAppending, True) Do While (remaining > 0) If remaining > 32768 then f2.Write f1.Read(32786) remaining = remaining - 32768 Else f2.Write f1.Read(remaining) remaining = 0 End If Loop End If End Function -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #8 (permalink) |
| | Re: vbscript equivalent of copy a+b c Hi Tom, Quote: > What I'm looking for is the VBS equivalent of the prompt command > COPY A.TXT+B.TXT C.TXT > where in the end the file C contains te content of A and B. Quote: >AFAIK, there is still no append method available to scripting. I >wrote this subroutine many, many years ago to do the job ... Quote: >' Appends file2 to end of file1 >Sub AppendFile(sFileSpec1, sFileSpec2) >dim fso > set fso = CreateObject("Scripting.FileSystemObject") > With .OpenTextFile(sFileSpec1, 8) > .Write fso.OpentextFile(sFileSpec2, 1).ReadAll > End With >End sub fragment to the central log. Quote: >This approach works fine for reasonably sized files, say less than >tens of megabytes, though there is almost no memory limitation, since >it is based on virtual (paging) memory, not strictly available RAM. >Very large files are just slower to copy over. few kilobytes. Bonno Bloksma |
My System Specs![]() |
| | #9 (permalink) |
| | Re: vbscript equivalent of copy a+b c Hi, Are you sure there are no errors in this sub? ----------<quote>----------------------------- AFAIK, there is still no append method available to scripting. I wrote this subroutine many, many years ago to do the job ... ' Appends file2 to end of file1 Sub AppendFile(sFileSpec1, sFileSpec2) dim fso set fso = CreateObject("Scripting.FileSystemObject") With .OpenTextFile(sFileSpec1, 8) .Write fso.OpentextFile(sFileSpec2, 1).ReadAll End With End sub ----------<quote>----------------------------- When I call the sub I get: Error: Invalid on unqualified reference Code 800A01F9 What should the code look like without the with statement? It looks like the With statment should maybe be With fso.OpenTextFile(sFileSpec1, 8) However, this stil fails if the central log for the day does not exist. It seems the OpenTextFile(sFileSpec1, 8) does not create a new empty file when not present. Maybe I need another test first and do a copy if this is the first append attempt of the day. Bonno Bloksma |
My System Specs![]() |
| | #10 (permalink) |
| | Re: vbscript equivalent of copy a+b c Bonno Bloksma schrieb: Quote: > Hi, > > Are you sure there are no errors in this sub? > Quote: > However, this stil fails if the central log for the day does not exist. It seems the > OpenTextFile(sFileSpec1, 8) does not create a new empty file when not present. Maybe I need another > test first and do a copy if this is the first append attempt of the day. Check the Docs for object.OpenTextFile(filename[, iomode[, create[, format]]]) and concentrate on the "create" parameter. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| vbscript to copy files from netlog to local profile folder | VB Script | |||
| Copy & paste from IE/FF into a new Outlook email via VBScript | VB Script | |||
| how-to run sequential copy processes thru vbscript | VB Script | |||
| Equivalent of powershell to vbscript command | PowerShell | |||
| equivalent to vbscript "." | PowerShell | |||