?
Solved

Create text file from VBSript

Posted on 2009-05-14
7
Medium Priority
?
843 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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