Question : vb insert space

Hello. I have a script that reads of a config file and retrieves file properties (file size,version&timestamp) and send the output to a txt file. How can i modify the script to include the following:
1. Currently timestamp and date are set to the current (when the script runs). Want it set to the last time the file being retrieved was modified.
2. include a space between each server output . For example, several servers are getting properties for adobe, others for java. Would like a space after the adobe output and before java.

Example output:
2/01/2009 2:02:19 PM: 10.x.x.1 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes                                                                                            
  (1 line space here)
2/01/2009 2:02:19 PM: 10.x.x.3 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.4 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes

3. Include a number count for each result.
Example:
1. 2/01/2009 2:02:19 PM: 10.x.x.4 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes
2. 2/01/2009 2:02:19 PM: 10.x.x.5 c:\Program Files\java\name.exe 1.0.0.1
2660352 Bytes

4. Move the size output line (example below) to the same line. Currently, the file size in the output is showing up on the next line
 
Example:
2/01/2009 2:02:19 PM: 10.x.x.1 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes
2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1
2660352 Bytes                                                                  
     (should be)
1. 2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1 2660352 Bytes
2. 2/01/2009 2:02:19 PM: 10.x.x.2 c:\Program Files\adobe\name.exe 1.0.0.1 2660352 Bytes

script:

Dim strServer
Dim strUsername
Dim strPassword
Dim StrFilename
Dim fConfig
dim objNetwork

Const ForReading = 1

Set objNetwork = CreateObject("WScript.Network")

strOutputFile = "C:\outputfile.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

set fConfig = objFSO.OpenTextFile("config.txt",ForReading, False)

Set objOutputFile = objFSO.CreateTextFile( strOutputFile, True, True )

do until fconfig.atendofstream
      strLine = fconfig.readline
      If UCase(Left(strLine, 6)) = "SERVER" Then strServer = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "USERNAME" Then strUsername = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "PASSWORD" Then strPassword = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "FILENAME" Then strFileName = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If strServer <> "" And strUsername <> "" And strPassword <> "" And strFileName <> "" Then
            If Ping(strServer) = True Then
                  processfile strServer, strUsername, strPassword, "z:\" & StrFilename
            Else
                  objOutputFile.WriteLine strServer & " is offline."
            End If
            strServer = ""
            strUsername = ""
            strPassword = ""
            strFileName = ""
      End If
Loop

objOutputFile.Close
MsgBox "finished."

Function ProcessFile(strSvr, strUser, strPass, strFilePath)
      Dim strMsg, strVersion, timestamp
      On Error Resume Next
      objnetwork.removenetworkdrive "z:", True, True
      Err.Clear
    objnetwork.mapnetworkdrive "z:", "\\" & strSvr & "\C$", False, strUser, strPass
    If Err.Number <> 0 Then
          MsgBox "Error mapping to " & strSvr & ". Please check you can map to the server." & VbCrLf & "Error " & Err.Number & ": " & Err.Description
          Err.Clear
    Else
          On Error GoTo 0
            ' Make sure the file exists
            If objFSO.FileExists( strFilePath ) = False Then
                  strMsg = strFile & " - File not found. "
            Else
                  ' Get the Version of the File and put it in a Message String
                  strVersion = objFSO.GetFileVersion(strFilePath)
                  strMsg = strSvr & " " & strFilePath & " " & strVersion
                  strtimestamp = time()
            End If
      
            ' Write the Message string to the Output File (with a CR LF)
            objOutputFile.Write Now & ": " & strMsg & VbCrLf
            Set ffile = objfso.getfile(strFilePath)
            objoutputfile.writeline ffile.size & " Bytes"
            
      End If
      objnetwork.removenetworkdrive "z:", True, True
      Err.Clear
      On Error GoTo 0
End Function

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function

Thanks in advance.

Answer : vb insert space

Hi, I've tested this a bit....give this a shot.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
Dim strServer
Dim strUsername
Dim strPassword
Dim StrFilename
Dim fConfig
Dim objNetwork
Dim strPreviousFileName
Dim intProgramCounter

strPreviousFile = ""
intProgramCounter = 0

Const ForReading = 1

Set objNetwork = CreateObject("WScript.Network")

strOutputFile = "outputfile.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

set fConfig = objFSO.OpenTextFile("config.txt",ForReading, False)

Set objOutputFile = objFSO.CreateTextFile( strOutputFile, True, True )

do until fconfig.atendofstream
      strLine = fconfig.readline
      If UCase(Left(strLine, 6)) = "SERVER" Then strServer = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "USERNAME" Then strUsername = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "PASSWORD" Then strPassword = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If UCase(Left(strLine, 8)) = "FILENAME" Then strFileName = Trim(Mid(strLine, InStr(strLine, "=") + 1))
      If strServer <> "" And strUsername <> "" And strPassword <> "" And strFileName <> "" Then
            If Ping(strServer) = True Then
                  'processfile strServer, strUsername, strPassword, "z:\" & StrFilename
                  processfile strServer, strUsername, strPassword, strFilename
            Else
                  objOutputFile.WriteLine strServer & " is offline."
            End If
            strServer = ""
            strUsername = ""
            strPassword = ""
            strFileName = ""
      End If
Loop

objOutputFile.Close
MsgBox "Finished. Please see " & strOutputFile

Function ProcessFile(strSvr, strUser, strPass, strFilePath)
	Dim strMsg, strVersion, timestamp, strDriveLetter
	On Error Resume Next
	objnetwork.removenetworkdrive "z:", True, True
	Err.Clear
	strDriveLetter = Left(strFilePath, 1) & "$"
	objnetwork.mapnetworkdrive "z:", "\\" & strSvr & "\" & strDriveLetter, False, strUser, strPass
	If Err.Number <> 0 Then
		MsgBox "Error mapping to " & strSvr & ". Please check you can map to the server." & VbCrLf & "Error " & Err.Number & ": " & Err.Description
		Err.Clear
	Else
		On Error GoTo 0
		' Make sure the file exists
		intProgramCounter = intProgramCounter + 1
		If objFSO.FileExists("Z:\" & Mid(strFilePath, 4)) = False Then
			strMsg = strFilePath & " - File not found. "
		Else
			' Get the Version of the File and put it in a Message String
			strVersion = objFSO.GetFileVersion("Z:\" & Mid(strFilePath, 4))
			' Write the Message string to the Output File (with a CR LF)
			Set ffile = objfso.getfile("Z:\" & Mid(strFilePath, 4))
			strtimestamp = ffile.DateLastModified
			If LCase(strPreviousFileName) <> LCase(Mid(Mid(strFilePath, 4), InStrRev(Mid(strFilePath, 4), "\") + 1)) Then
				intProgramCounter = 1
				objOutputFile.WriteLine ""
			End If
			strMsg = intProgramCounter & ". " & strtimestamp & " " & strSvr & " " & strFilePath & " " & strVersion & " " & ffile.size & " Bytes"
		End If
		objOutputFile.WriteLine strMsg
		strPreviousFileName = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
	End If
	objnetwork.removenetworkdrive "z:", True, True
	Err.Clear
	On Error GoTo 0
End Function

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
Random Solutions  
 
programming4us programming4us