Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating CSV format text file

Status
Not open for further replies.

FrankEnc

IS-IT--Management
Jan 18, 2006
1
US
Hi,
I'm having difficulties finding out how to get this script to save my text file into CSV formatted text file. I've tried just changing the *.TXT extension to a *.CSV but it still creates a text file by default. Perhaps there is a special CSV text file command but I'm new to VBScript and I'm trying to modify this script as I'm a Server administrator and I need to be notified when hard drive space starts dipping below 80% of capacity. Any suggestions would be welcomed. Thank you. Frank

Code:

computers = Array( "")
set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists ("c:\Test10.txt") Then
set file_name = objFSo_OpentextFile("c:\Test10.txt", 2)
Else
set file_name = objFSO.CreateTextFile("c:\Test10.txt")
End If
problem = 0
For Each Computer In computers
On Error Resume Next
Dim cnt
Set objWMIService = GetObject ("winmgmts://" & computer)
if Err <> 0 Then
file_name.WriteLine ( "**" & Err.Number & " " & Err.Description & "**" )
file_name.WriteBlanklines (2)
Err.clear
Else
file_name.WriteLine ("Details For Computer " & Computer)
set colobjdisk = objWMIService.ExecQuery ("Select * FROM Win32_LogicalDisk")
cnt = 0
For Each disk In colobjdisk
file_name.WriteLine ("disk id " & disk.DeviceId & " Type " & disk.DriveType)
Select case disk.DriveType
Case 1
Case 2
Case 3
value = Int(disk.Size/1048576)
threshold = Int(value * .20 )
FreeMegabytes = Int(disk.Freespace/1048576)

If FreeMegabytes < 300 Then
cnt = cnt + 1
problem = problem + 1
file_name.WriteLine ( "Drive " & disk.DeviceId & _
" On Computer " & Computer & " have less then 300 MB")
End If

If FreeMegabytes < threshold Then
cnt = cnt + 1
file_name.WriteLine ( "Drive " & disk.DeviceId & _
" On Computer " & Computer & " is more then 80% Full")
End If
Case 4
Case 5
Case 6
End Select
Next
End If
If cnt = 0 Then
File_name.WriteLine ("The File Systems In this Machine are less Then 80% Full")
End If
file_name.WriteBlankLines (2)
Next
file_name.close

 
But what you are writing to the file is not csv-concious, and what you intended to record is not planned for csv-aware solftware/script to retrieve data.

This is what csv format is:
It is a plain text file with some definitive way to store data for easy retrieval. So you just have to plan out what kind of data you want to be written to it and at which fields.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top