append data in txt file

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

append data in txt file

Post by sal21 »

I have in a dir c:\myfile\ many txt file.
Is possible to open one and append from the last free line a new data, save it, close and exit...
Thah is all :grin: :scratch:

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: append data in txt file

Post by HansV »

Do you want to append the same text to all files?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: append data in txt file

Post by sal21 »

HansV wrote:Do you want to append the same text to all files?
Sorry me... but this is a stupid question, i know well this method, tks Hans.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: append data in txt file

Post by HansV »

So you'll work it out for yourself?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: append data in txt file

Post by sal21 »

HansV wrote:So you'll work it out for yourself?
YES i can make the code myself, tks for assitence :thankyou:

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: append data in txt file

Post by sal21 »

HansV wrote:So you'll work it out for yourself?
sorry if i post on old th3d...

but really no!

with command in CICS procedure i select many report (Are all a txt file) approx 10/12

from a similar loop for next in CICS command i send to c:\mydir\a.txt, c:\mydir\b.txt, c:\mydir\c.txt, ... ecc until the 12Th file is created.

The file are little dimension approx 900 kb

during the loop a need to append from the fist file saved, for example c:\mydir\a.txt, the subsequent other file...

example:

c:\mydir\a.txt is finished, append to the atxt the b.txt, the b.txt is finished append c.txt ecc...

note:
with a code i can test when the job of txt is finished

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: append data in txt file

Post by HansV »

You could use the following macro:

Code: Select all

Sub AppendFiles(strFile1 As String, strFile2 As String)
   ' Run the DOS Copy command to append the text files.
   Shell "command.com /c copy """ & strFile1 & """+""" & _
       strFile2 & """ """ & strFile1 & """ /b"
End Sub
Call it like this:

AppendFiles "C:\MyDir\a.txt", "C:\MyDir\b.txt"
AppendFiles "C:\MyDir\a.txt", "C:\MyDir\c.txt"
...
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: append data in txt file

Post by sal21 »

HansV wrote:You could use the following macro:

Code: Select all

Sub AppendFiles(strFile1 As String, strFile2 As String)
   ' Run the DOS Copy command to append the text files.
   Shell "command.com /c copy """ & strFile1 & """+""" & _
       strFile2 & """ """ & strFile1 & """ /b"
End Sub
Call it like this:

AppendFiles "C:\MyDir\a.txt", "C:\MyDir\b.txt"
AppendFiles "C:\MyDir\a.txt", "C:\MyDir\c.txt"
...
OPS!!!
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: append data in txt file

Post by HansV »

Does this work?

Code: Select all

Sub AppendFiles(strFile1 As String, strFile2 As String)
   ' Run the DOS Copy command to append the text files.
   Shell "cmd /c copy """ & strFile1 & """+""" & _
       strFile2 & """ """ & strFile1 & """ /b"
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: append data in txt file

Post by sal21 »

HansV wrote:Does this work?

Code: Select all

Sub AppendFiles(strFile1 As String, strFile2 As String)
   ' Run the DOS Copy command to append the text files.
   Shell "cmd /c copy """ & strFile1 & """+""" & _
       strFile2 & """ """ & strFile1 & """ /b"
End Sub

WORK PERFECT!!!!!!!!!!!!!!!!!!!!!

but if i'm wrong i have see for one sec a msdos windows, possible?

if yes possible to suppress?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: append data in txt file

Post by HansV »

Try

Code: Select all

Sub AppendFiles(strFile1 As String, strFile2 As String)
   ' Run the DOS Copy command to append the text files.
   Shell "cmd /c copy """ & strFile1 & """+""" & _
       strFile2 & """ """ & strFile1 & """ /b", vbHide
End Sub
Best wishes,
Hans