+ Post New Thread
Page 3 of 3 FirstFirst 123
Results 31 to 39 of 39
Scripts Thread, vbscript to find a string value in a text file and then write an answer in Coding and Web Development; can you port the full script that you are using in case i have mistyped something...
  1. #31

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    can you port the full script that you are using in case i have mistyped something

  2. #32

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,487
    Thank Post
    1,445
    Thanked 1,182 Times in 809 Posts
    Rep Power
    709
    Quote Originally Posted by NETKILLER View Post
    can you port the full script that you are using in case i have mistyped something
    No problem, the final script I have after all our modifications is this one:

    Code:
    Dim FSO, LogFile, rdFile
    Dim bFound as boolean
    
    Set FSO = CreateObject ("Scripting.FileSystemObject")
    
    objStartFolder = "C:\test\"
    
    Set LogFile = FSO.CreateTextFile("C:\test\packageinstallcheck.txt",True)
    Set objFolder = FSO.GetFolder(objStartFolder)
    
    LogFile.writeLine objFolder.Path
    
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    	LogFile.writeLine objFile.Name
    Next
    
    LogFile.writeLine Echo
    
    ShowSubfolders FSO.GetFolder(objStartFolder)
    
    
    Sub ShowSubFolders(Folder)
    	For Each Subfolder in Folder.SubFolders
    		LogFile.writeLine Subfolder.Path
    		
    		Set objFolder = FSO.GetFolder(Subfolder.Path)
    		Set colFiles = objFolder.Files
    		
    		For Each objFile in colFiles
    			LogFile.Write objFile.Name
    			
    			Set rdFile = FSO.OpenTextFile(objFile.Path, 1)
    			bFound = False
    			Do Until rdFile.AtEndOfStream
    				srtContents = rdFile.ReadLine
    				if InStr(1, strContents, "success or error status: 0", 0) > 0 Then 
    					bFound = True
    					Exit Do
    				end if
    			Loop
    			rdFile.Close
    			
    			if bFound = True Then 
    				LogFile.Write ", Yes" & Chr(10)
    				LogFile.WriteLine Echo
    			else
    				LogFile.Write ", No" & Chr(10)
    				LogFile.WriteLine Echo
    			end if
    		Next
    		
    		LogFile.writeLine Echo
    		ShowSubFolders Subfolder
    	Next
    End Sub
    EDIT: please remember to change the file paths at the start of that script, they are the folders I set up on my machine for testing

  3. #33

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    doesn't seem to like this line

    Dim bFound as boolean

    (2, 12) Microsoft VBScript compilation error: Expected end of statement

    I have all the luck........

  4. #34

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by NETKILLER View Post
    doesn't seem to like this line

    Dim bFound as boolean

    (2, 12) Microsoft VBScript compilation error: Expected end of statement

    I have all the luck........
    No such thing as boolean in this script, Change it to: Dim bFound

    Steve

  5. Thanks to Steve21 from:

    NETKILLER (21st July 2011)

  6. #35

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,487
    Thank Post
    1,445
    Thanked 1,182 Times in 809 Posts
    Rep Power
    709
    I'm completely stumped, that line is crashing out the script on my machine too. I've omitted it and now it returns "no" for all files for me too... I'm sure I tested it earlier... the "ReadAll" method definitely worked for me earlier, I know I tested that one...

  7. #36

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    That’s it i must be jinxed, have made that change and Just done the WScript.Echo srtContents test
    and
    It has gone back to saying no at the end of each line and now getting a blank message box again.

    That’s it I am going to go home having the rest of last nights pizza and having a look again after food

  8. #37

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,487
    Thank Post
    1,445
    Thanked 1,182 Times in 809 Posts
    Rep Power
    709
    Quote Originally Posted by LosOjos View Post
    I'm completely stumped, that line is crashing out the script on my machine too. I've omitted it and now it returns "no" for all files for me too... I'm sure I tested it earlier... the "ReadAll" method definitely worked for me earlier, I know I tested that one...
    And now not even that version of the script is working for me sorry!

  9. Thanks to LosOjos from:

    NETKILLER (21st July 2011)

  10. #38

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Hey Steve21 and LosOjos

    good news i have got the script working, i am running some final test and adding come comments once it is done i will post it thank you both for you help

  11. #39

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    please find below the script that will search in files for a string value in folder and its sub folders

    Dim FSO, LogFile, rdFile
    Dim bFound, srtContents, installed

    Set FSO = CreateObject ("Scripting.FileSystemObject")

    'This part of the code will get the current date and time this
    'will be used for adding to the log file name so to create a unique name
    'So that the name can conform to windows name convention
    'it will then proceed to remove the / in the date and then the : in the time
    'this will then leave you with the following DDMMYYYY HHMMSS

    'start of date and time formatting

    'gets the current system time and date
    datentime = Now()
    'removes the / from the date part of the string
    dateformated = Replace(datentime, "/", "")
    'removes the : from the time part of the string
    datentimeformated = Replace(dateformated, ":", "")

    'end of date and time formatting

    'set the server and package log locations here
    'set server
    server = "server name"
    'set package log location
    packagelogs = "packageinstalllogs$"


    'this uses the preset server and package log location from above
    objStartFolder = "\\" & server & "\" & packagelogs

    'set the location of the applogchecker log file
    '
    applogcheckerlocation = "appdeployment\applogchecker"

    Set LogFile = FSO.CreateTextFile("\\" & server & "\" & applogcheckerlocation & "\appinstallcheckerlog" & " " & datentimeformated & ".txt",True)
    Set objFolder = FSO.GetFolder(objStartFolder)

    LogFile.writeLine objFolder.Path

    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    LogFile.writeLine objFile.Name
    Next

    LogFile.writeLine Echo

    ShowSubfolders FSO.GetFolder(objStartFolder)

    Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
    LogFile.writeLine Subfolder.Path

    Set objFolder = FSO.GetFolder(Subfolder.Path)
    Set colFiles = objFolder.Files

    For Each objFile in colFiles
    LogFile.Write Subfolder.Path & objFile.Name
    Set rdFile = FSO.OpenTextFile(objFile.Path, 1, TristateFalse, -1)
    bFound = "False"
    installed = "success or error status: 0."
    Do Until rdFile.AtEndOfStream
    srtContents = rdFile.ReadLine
    If inStr(1, srtContents, installed) > 0 Then
    bFound = "True"
    Exit Do
    end If
    Loop
    rdFile.Close

    if bFound = "True" Then
    LogFile.Write ", Yes" & Chr(10)
    LogFile.WriteLine Echo
    else
    LogFile.Write ", No" & Chr(10)
    LogFile.WriteLine Echo
    end if
    Next
    LogFile.writeLine Echo
    ShowSubFolders Subfolder
    Next
    End Sub
    WScript.Echo "log complete"

SHARE:
+ Post New Thread
Page 3 of 3 FirstFirst 123

Similar Threads

  1. Replies: 8
    Last Post: 5th August 2010, 10:04 AM
  2. List computers in Domain in a text file with vbs
    By FatBoy in forum How do you do....it?
    Replies: 5
    Last Post: 15th February 2010, 12:29 PM
  3. Replies: 7
    Last Post: 29th September 2009, 06:04 PM
  4. Where do I look to find a job in a school in London area?
    By alena in forum Educational IT Jobs
    Replies: 2
    Last Post: 26th February 2008, 01:21 PM
  5. How to find Command Bar ID's in Office 2003
    By originofsymmetry in forum How do you do....it?
    Replies: 1
    Last Post: 15th July 2007, 10:41 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •