Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


ForAppending & ForWriting

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,47408
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> ForAppending & ForWriting
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 ForAppending & ForWriting - 5/22/2007 7:21:59 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
With regards to text files, what's the difference between the above 2 constants?
 
 
Post #: 1
 
 RE: ForAppending & ForWriting - 5/22/2007 7:25:45 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
ForReading opens a file for reading (i.e. you can't write to it)

ForWriting either opens an existing file in write mode (overwriting it if it's already there) or creating a new file for writing if it doesn't exist.

You also have ForAppending (value of 8) which will open an existing file for writing and lets you append text to the end of the file

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to markmcrobie)
 
 
Post #: 2
 
 RE: ForAppending & ForWriting - 5/22/2007 7:38:44 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
So, as per my original question in the subject line, I'm still confused about the actual difference between the 2.

Thanks

(in reply to ginolard)
 
 
Post #: 3
 
 RE: ForAppending & ForWriting - 5/22/2007 7:45:44 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
What's confusing?  ForReading opens a file so that it can be read, ForWriting opens a file so that it can be written to/created.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to markmcrobie)
 
 
Post #: 4
 
 RE: ForAppending & ForWriting - 5/22/2007 8:10:28 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
gino, I'm guessing you're maybe not awake properly yet!

I know what ForReading does.  Read my subject line again.

:-)

(in reply to ginolard)
 
 
Post #: 5
 
 RE: ForAppending & ForWriting - 5/22/2007 8:14:43 PM   
  ginolard


Posts: 1082
Score: 21
Joined: 8/10/2005
Status: offline
Ahem, yes, not awake.

Still, my post did answer your question.

ForWriting will either

a) Open an existing text file for writing and will overwrite it (i.e. any existing content will be lost)
b) Create a new file for writing if it doesn't already exist

ForAppending will open an existing for writing and allow you to add text to whatever is already there.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to markmcrobie)
 
 
Post #: 6
 
 RE: ForAppending & ForWriting - 5/22/2007 8:23:33 PM   
  markmcrobie

 

Posts: 314
Score: 0
Joined: 12/12/2006
Status: offline
got it, thanks.

So when using ForWriting, at what point is the existing content lost forever? Is it as soon as you Set a text file object with the ForWriting constant? Or is it only lost once you start actually writing to it? Or is it only when you save/close it?

(in reply to ginolard)
 
 
Post #: 7
 
 RE: ForAppending & ForWriting - 5/22/2007 11:39:17 PM   
  mbouchard


Posts: 1924
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
I just ran a quick test and as soon as the file was opened it was empty.


      

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to markmcrobie)
 
 
Post #: 8
 
 RE: ForAppending & ForWriting - 5/23/2007 1:17:12 AM   
  DiGiTAL.SkReAM


Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Since I come from a background of batch files, it is always easiest for me to think of them this way.
ForAppending is the same as doing this in a batch file:
dir c: >> d:\output.txt

while ForWriting is the same as doing this in a batch file:
dir c: > d:\output.txt


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to mbouchard)
 
 
Post #: 9
 
 RE: ForAppending & ForWriting - 5/23/2007 2:04:13 AM   
  mcds99


Posts: 441
Score: 4
Joined: 2/28/2006
Status: offline
When you append you add to any existing content, writting occurs after the last existing line.

When you write you overwrite any existing content, writting occurs at line 1 character 1.

_____________________________

Sam

Keep it Simple Make it Fun KiSMiF

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> ForAppending & ForWriting Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts