File System Object question

P

PedroX

I have about 200 documents to which I need to write a header and a footer.
Appending (the footer) is easy, but I cannot figure out how to write to the
very beginning of the file. Any help would be appreciated
 
C

Curt_C [MVP]

PedroX said:
I have about 200 documents to which I need to write a header and a footer.
Appending (the footer) is easy, but I cannot figure out how to write to the
very beginning of the file. Any help would be appreciated

put your new text into a string1,
read in the contents of the doc to string2
string1 = string1 + string2
save string1 back to the doc.
 
M

McKirahan

PedroX said:
I have about 200 documents to which I need to write a header and a footer.
Appending (the footer) is easy, but I cannot figure out how to write to the
very beginning of the file. Any help would be appreciated

Your "documents", I gather, are text files and not MS-Word documents.

You'll have to "rewrite" to entire text file.

Use the ReadAll method to read the intial file then write your header,
the initial file, and the footer to the same file.
 
P

PedroX

Use the ReadAll method to read the intial file then write your header,
the initial file, and the footer to the same file.

Thanks 4 the replies. I guess that should work. The documents are XML files.
They are about 10 mb each. Would that be a problem?
 
B

Bob Barrows [MVP]

PedroX said:
Thanks 4 the replies. I guess that should work. The documents are XML
files. They are about 10 mb each. Would that be a problem?

Please don't crosspost to so many groups. This question had nothing to do
with databases (db) or components, so it was certainly off-topic in those
groups, which I've removed from this reply.

If you had mentioned from the start that you were using XML files, you would
have received a different answer. FileSystemObject is not necessary for
modifying XML . I suggest you provide a small example of what you want to
do. Are you really adding information outside of the XML? Or are you adding
nodes to the XML?

Bob Barrows
 
R

Roland Hall

in message : : > I have about 200 documents to which I need to write a header and a
footer.
: > Appending (the footer) is easy, but I cannot figure out how to write to
: the
: > very beginning of the file. Any help would be appreciated
:
: Your "documents", I gather, are text files and not MS-Word documents.
:
: You'll have to "rewrite" to entire text file.
:
: Use the ReadAll method to read the intial file then write your header,
: the initial file, and the footer to the same file.

If you were going to do that, wouldn't this be easier?

sub appendit(file1, file2, file3, t)
dim fso, temp, tempFile, wshShell, oExec
set fso = CreateObject("Scripting.FileSystemObject")
set wshShell = CreateObject("WScript.Shell")
if fso.FileExists(file1) then
if fso.FileExists(file2) then
if fso.FileExists(file3) then
temp = fso.GetTempName
set oExec = wshShell.Exec("%comspec% /c copy " & file1 & "+" & file2
& "+" & file3 & " " & temp)
do while oExec.status = 0
wscript.sleep 100
loop
if fso.FileExists(t) then
fso.DeleteFile(t)
end if
fso.MoveFile temp, t
end if
end if
end if
wscript.echo temp
end sub

appendit "f1.txt","f2.txt","f3.txt","f4.txt"

f4.txt would be replace with the file you wanted to end up with, however, I
wouldn't use this for XML files.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top