Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create text file from VBSript

Posted on 2009-05-14
7
Medium Priority
?
850 Views
Last Modified: 2012-05-07
I have been tasked with writing a VBScript that is being used to determine if our corporate antivirus definitions are over 7 days old.  This will be  used by our management platform to automatically generate an alert.  I have been able to get it where it generates the output into a pop up window, but I need it to create a text file called vipreage.txt on the C: drive.  I have been trying  to find an answer to this but scripting has never been a strong suit of mine.  Any help would be greatly appreciated.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\Program Files\Sunbelt Software\SBEAgent\Definitions\defver.txt")
wscript.echo DateDiff("d", objFile.DateLastModified, Now())

Open in new window

0
Comment
Question by:sdipietro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Expert Comment

by:satheeshm
ID: 24388333
Hi,

You are near to solution. you can create text file using file system object. Check the below code sample.

dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
0
 

Author Comment

by:sdipietro
ID: 24388361
satheeshm,

Would that just be added below the existing text?
0
 
LVL 9

Assisted Solution

by:gregcmcse
gregcmcse earned 248 total points
ID: 24388478
Replace the "wscript.echo" line with these lines:
set myFile = objFSO.CreateTextFile("c:\vipreage.txt",True)
myFile.WriteLine DateDiff("d", objFile.DateLastModified, Now())
myFile.Close
set myFile = Nothing
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
satheeshm earned 252 total points
ID: 24388517
no.. it creates a new file. you want create new file or you want to append to an existing text file.

to create a new file use the below code. I added code to your existing code.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\Program Files\Sunbelt Software\SBEAgent\Definitions\defver.txt")
wscript.echo DateDiff("d", objFile.DateLastModified, Now())
dim fname
set fname=fs.CreateTextFile("c:\vipreage.txt",true)
fname.WriteLine("Hello World!") \\ Change this to what ever you want to write into the file
fname.Close
set fname=nothing
set objFSO=nothing
0
 
LVL 5

Expert Comment

by:satheeshm
ID: 24388527
okay.. if you dont want alert remove the echo from that code
0
 
LVL 9

Expert Comment

by:gregcmcse
ID: 24388668
If you want to append to your output file rather than overwrite it everytime, change it to this:
ForAppending = 8
set myFile = objFSO.OpenTextFile("c:\vipreage.txt", ForAppending,True)
myFile.WriteLine DateDiff("d", objFile.DateLastModified, Now())
myFile.Close
set myFile = Nothing
0
 

Author Comment

by:sdipietro
ID: 24420954
Thanks Guys!  I was able to get the script working by using what you both gave me.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question