-
May 13th, 2002, 04:42 AM
#1
read and append text file details to onother text file
i have three text files and i want to read staff from the other two and append it to one .how do i do it??
when opportunities arises ,only the prepared mind is fovoured
-
May 13th, 2002, 04:47 AM
#2
Re: read and append text file details to onother text file
Try this...
Dim FFileIn as Long, FFileOut as Long
FFileOut = FreeFile
Open "c:\output.txt" for Output as #FFileOut
FFileIn = FreeFile
Open "c:\input1.txt" for input as #FFileIn
print #FFileOut, input(FileLen("c:\input1.txt"),FFileIn)
Close #FFileIn
FFileIn = FreeFile
Open "c:\input2.txt" for input as #FFileIn
print #FFileOut, input(FileLen("c:\input2.txt"),FFileIn)
Close #FFileIn
FFileIn = FreeFile
Open "c:\input3.txt" for input as #FFileIn
print #FFileOut, input(FileLen("c:\input3.txt"),FFileIn)
Close #FFileIn
Close #FFileOut
This will read the content of input1.txt, input2.txt and input3.txt and write it to output.txt
Tom Cannaerts
slisse@planetinternet.be.remove.this.bit
Moderator on http://www.vbcodelibrary.co.uk/board
A bottomless pit, I'm sure it came with the place, who would dig one on purpose?
-
August 15th, 2002, 01:12 PM
#3
Appending Text Files
I came across this thread in a search. I also need to append several text files into one text file. This codes works very well.
My questions:
- Instead of hardcoding the filenames, how do I just specify a certain directory where the input files are located?
- If I just use the directory, I want to be able to vary the number of files.
Any help will be appreciated.
SB
-
August 15th, 2002, 02:38 PM
#4
To use non-static folder and filename, as an example, use variable:
Change:
Open "c:\input1.txt"
For:
strFolderName = "C:\"
strFileName = "input1.txt"
Open strFolderName & strFileName
If you want to return all the files from a specific folder, you can do it two ways, first by using DIR() function, second by using FileSystemObject :
Code:
'Add a reference to Microsoft Scripting Runtime
Dim fso As new FileSystemObject
Dim objFolder As Folder
Dim objFile As File
'Get the folder you want, can be "C:\"
Set objFolder = fso.GetFolder(strFolderName)
'Browse each files in the folder
For Each objFile In objFolder.Files
'Do your stuff here
Next
JeffB
-
August 15th, 2002, 03:47 PM
#5
Thanks Jeff B - this works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|