Well i have to edit multiple files situated in diffrent locations in the computer i know it can be done using the command [open "C:\file.txt" for append as #1] but my problem is that i have to append the same lines in the other files also so is there a way that i can append the same lines at a time to all the files [i am a lazy person i dont like to type much & any way i need my program to be small and fast] so is there a way to open multiple files and append all of the at once i tried doing thins but it didnt work
open "C:\file.txt" for append as #1
open "D:\file123.txt" for append as #1
Print #1, "hi Blha Blha BLHA"
close #1
but the ompiler returned some error
Multiple files appending
Code: Select all
stri$ = "Hello, World!"
open "C:\file.txt" for append as #1
open "D:\file123.txt" for append as #2
Print #1, stri$
Print #2, stri$
close #1 , #2
Code: Select all
dim flist(5) as string
flist(0) = "C:\file.txt"
flist(1) = "C:\blarga"
flist(2) = "C:\poof\tjoff"
flist(3) = "C:\Yadda"
flist(4) = "C:\random\random\whatever\file.txt"
flist(5) = "D:\otherhd\blipp"
stri$ = "Hello, World!"
for a = 0 to 5
open flist(a) for append as #1
Print #1, stri$
close #1
next
I have left this dump.
I think this works better:
I use it a lot. I don't think many people know that you can use a variable after the # when referring to files.
Code: Select all
dim flist(6) as string
flist(1) = "C:\file.txt"
flist(2) = "C:\blarga"
flist(3) = "C:\poof\tjoff"
flist(4) = "C:\Yadda"
flist(5) = "C:\random\random\whatever\file.txt"
flist(6) = "D:\otherhd\blipp"
stri$ = "Hello, World!"
for a = 1 to 6
open flist(a) for append as #a
next a
for a = 1 to 6
Print #a, stri$
next a
'do other stuff here. you can post to all the files as much as you want using the above method
for a = 1 to 6
close #a
next a
If you need music composed in MP3, WAV, or MIDI format, please contact me via email.
Xerol's Music - Updated Regularly!
Xerol's Music - Updated Regularly!
You should use another array and store the file id in it, to get a valid fileid use FREEFILE.
But, your way will fail, as you can only open ~16 or so files, as specified in the config.sys file (iirc)
Mine is set to 32 for example..
The way I posted does the same thing, using less memory and less resources overall, it's always a good idea to keep as few files open as possible..
But, your way will fail, as you can only open ~16 or so files, as specified in the config.sys file (iirc)
Mine is set to 32 for example..
The way I posted does the same thing, using less memory and less resources overall, it's always a good idea to keep as few files open as possible..
I have left this dump.
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
you took the words straight out of my mouth.Z!re wrote:You should use another array and store the file id in it, to get a valid fileid use FREEFILE.
But, your way will fail, as you can only open ~16 or so files, as specified in the config.sys file (iirc)
Mine is set to 32 for example..
The way I posted does the same thing, using less memory and less resources overall, it's always a good idea to keep as few files open as possible..
Right, Z!re's method is much simpler, easy to understand, and certainly will get the job done for ant number of files with no complications.
Nice work, Z!re!
BTW, Zerol, in your version, you don't need the FOR loop at the end to close the files. Just a simple CLOSE with no parameters will close all the files. As a matter of fact, unless the program is going to open any other files afterwards, you can just do an END or SYSTEM which will also close all the files, or code nothing at the end of the code, which does this by default.
*****
Nice work, Z!re!
BTW, Zerol, in your version, you don't need the FOR loop at the end to close the files. Just a simple CLOSE with no parameters will close all the files. As a matter of fact, unless the program is going to open any other files afterwards, you can just do an END or SYSTEM which will also close all the files, or code nothing at the end of the code, which does this by default.
*****
Last edited by moneo on Thu Sep 29, 2005 7:04 pm, edited 1 time in total.
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.