Go Back   Computer Forums > General Computing > Hardware
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 08-23-2009, 04:21 PM   #1
Solid State Member
 
Join Date: Jun 2009
Posts: 19
Default How can i make a vbscript type in a text file.

For example, lets say i have a file example.txt in my Local Drive. What would be the script to write "Hello" in the example.txt file?
__________________

shrshr429 is offline   Reply With Quote
Old 08-23-2009, 04:26 PM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: How can i make a vbscript type in a text file.

One of my favourite websites answers this one best (as it does lots of other things! A really good one to bookmark.)

http://www.rgagnon.com/wshdetails/wsh-0003.html
__________________

berry120 is offline   Reply With Quote
Old 08-23-2009, 05:09 PM   #3
Solid State Member
 
Join Date: Jun 2009
Posts: 19
Default Re: How can i make a vbscript type in a text file.

Dim objFileSystem, objOutputFile
Dim strOutputFile

Const OPEN_FILE_FOR_APPENDING = 8

' generate a filename base on the script name
strOutputFile = "./writefile.out"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, _
OPEN_FILE_FOR_APPENDING)

objOutputFile.WriteLine("Hello world (" & Now & ")")
objOutputFile.Close

Set objFileSystem = Nothing

WScript.Quit(0)

I found that, but im not 100% on how it would work. For example if the file was still at c:\example.txt where would i put that in the script?
shrshr429 is offline   Reply With Quote
Old 08-23-2009, 05:49 PM   #4
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: How can i make a vbscript type in a text file.

Ah, fair point. It'd go in strOutputFile:
Code:
strOutputFile = "./writefile.out"
The one given there is using the *nix naming convention, if you're on a windows platform just change it accordingly to what you need
berry120 is offline   Reply With Quote
Old 08-23-2009, 06:20 PM   #5
Solid State Member
 
Join Date: Jun 2009
Posts: 19
Default Re: How can i make a vbscript type in a text file.

I somewhat figured it out, it'll add text to the file only if it is near it. For example, if the vbs file was located in my documents folder then the text file i am adding has to be there as well. Is there anyway to change it so it will add text to a file in a different location. Anyone?

nevermind figured it out, thanks alot for the link!!
shrshr429 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:22 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0