+ Post New Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 39
Scripts Thread, vbscript to find a string value in a text file and then write an answer in Coding and Web Development; Originally Posted by NETKILLER Hey your right it does help see below Attachment 10859 Can you post full script you're ...
  1. #16

    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
    Hey

    your right it does help see below

    Attachment 10859
    Can you post full script you're using atm please will be easier to see it

    Also as a point, the script Los posted "won't" search any .txt files in the same directory as the script, only subfolders. So that may be the simple issue, if that's how you set it up?

    Steve

  2. #17

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    just getting a blank echo box now

  3. #18

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Full script

    Dim FSO, LogFile, rdFile

    Set FSO = CreateObject ("Scripting.FileSystemObject")

    objStartFolder = "\\server\packageinstalllogs$"

    Set LogFile = FSO.CreateTextFile("\\server\packageinstalllogs$\p ackageinstallcheckv6.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", 1) > 0 Then
    bFound = True
    Exit Do
    End If
    Loop
    rdFile.Close

    WScript.Echo strContents

    if bFound = True Then
    LogFile.Write objFile.Name & ", Yes" & Chr(10)
    LogFile.WriteLine Echo
    else
    LogFile.Write objFile.Name & ", No" & Chr(10)
    LogFile.WriteLine Echo
    end if
    Next

    LogFile.writeLine Echo
    ShowSubFolders Subfolder
    Next
    End Sub

  4. #19

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    the folder are set up as follows

    packagelogs
    PCname-0001
    software1.txt
    software2.txt
    software3.txt
    PCname-0002
    software1.txt
    software2.txt
    software3.txt

  5. #20

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Can you just try this script standalone not with the other one:

    Code:
    Dim FSO, LogFile, rdFile
    
    Set FSO = CreateObject ("Scripting.FileSystemObject")
    
    Set LogFile = FSO.CreateTextFile("PATHHERE\packageinstallcheck.txt",True)
    
    Set rdFile = FSO.OpenTextFile("PATHHERE\software1.txt", 1)
    strContents = rdFile.ReadAll
    rdFile.Close
    
    			
    if InStr(1, strContents, "success or error status: 0", 1) > 0 Then 
    LogFile.Write "Yes" & Chr(10)
    else
    LogFile.Write "No" & Chr(10)
    end if
    Put a direct path to one of the software.txt files in, and obviously reput your server paths back in.

    Just want to see if its something about the script, or if its something weird :P

    Thanks,
    Steve

  6. #21

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    hey

    the packageinstallcheck.txt file only has no in it

    the file that it was looking at was this (just end part)

    Property(S): SourcedirProduct = {10ABE49D-343A-463E-9753-C4C5A05ECEF9}
    Property(S): ProductToBeRegistered = 1
    MSI (s) (30:B0) [10:27:08:250]: Product: Sibelius Scorch (Firefox, Opera, Netscape only) -- Installation completed successfully.

    MSI (s) (30:B0) [10:27:08:250]: Windows Installer installed the product. Product Name: Sibelius Scorch (Firefox, Opera, Netscape only). Product Version: 6.2.0. Product Language: 1033. Manufacturer: Sibelius Software. Installation success or error status: 0.

    === Logging stopped: 15/07/2011 10:27:08 ===

  7. #22

    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
    hey

    the packageinstallcheck.txt file only has no in it

    the file that it was looking at was this (just end part)

    Property(S): SourcedirProduct = {10ABE49D-343A-463E-9753-C4C5A05ECEF9}
    Property(S): ProductToBeRegistered = 1
    MSI (s) (30:B0) [10:27:08:250]: Product: Sibelius Scorch (Firefox, Opera, Netscape only) -- Installation completed successfully.

    MSI (s) (30:B0) [10:27:08:250]: Windows Installer installed the product. Product Name: Sibelius Scorch (Firefox, Opera, Netscape only). Product Version: 6.2.0. Product Language: 1033. Manufacturer: Sibelius Software. Installation success or error status: 0.

    === Logging stopped: 15/07/2011 10:27:08 ===
    Very strange... That works fine here. Can you try running it locally on your computer with those files (aka C drive), cut out the network part.

    Could be something stupid like you don't have access to read those files through the script over the network.

    Especially if everything you try to access the file, your echo's are showing nothing.

    Steve

  8. #23

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    just looked and the encoding is set to unicode, i saved the file as ANSI and it worked so 2 options 1 can VBscript be told to understand unicode or 2 is there a way to convert the software.txt to ANSI

  9. #24

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    hey

    i have just change the following and it works

    Set rdFile = FSO.OpenTextFile(objFile.Path, 1,) to Set rdFile = FSO.OpenTextFile(objFile.Path, 1, TristateFalse, -1)

    but i think it is still not full working as i am now getting this error when i run it

    vbserror2.jpg

    the full script is below

    Dim FSO, LogFile, rdFile

    Set FSO = CreateObject ("Scripting.FileSystemObject")

    objStartFolder = "\\server\packageinstalllogs$"

    Set LogFile = FSO.CreateTextFile("\\server\packageinstalllogs$\p ackageinstallcheckv5.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, TristateFalse, -1)
    strContents = rdFile.ReadAll
    rdFile.Close

    'WScript.Echo strContents

    if InStr(1, strContents, "success or error status: 0.", 1) > 0 Then
    LogFile.Write objFile.Name & ", Yes"
    LogFile.writeLine Echo
    else
    LogFile.Write objFile.Name & ", No"
    LogFile.writeLine Echo
    end if
    Next

    LogFile.writeLine Echo
    ShowSubFolders Subfolder
    Next
    End Sub

  10. #25

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,491
    Thank Post
    1,448
    Thanked 1,191 Times in 812 Posts
    Rep Power
    710
    That error is usually when you've tried to read an empty text file.

    Try using the code I posted earlier to read line by line (but remembering to use your new OpenTextFile code) and it should work

  11. #26

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    hey

    no errors but is now putting no at the end of all the lines again

    when i run the script with WScript.Echo srtContents just after rdFile.Close i get his display


    vbserror3.jpg


    to me it might only be looking at that line see below the full script


    Dim FSO, LogFile, rdFile

    Set FSO = CreateObject ("Scripting.FileSystemObject")

    objStartFolder = "\\server\packageinstalllogs$"

    Set LogFile = FSO.CreateTextFile("\\server\packageinstalllogs$\p ackageinstallcheckv8.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, TristateFalse, -1)
    bFound = False
    Do Until rdFile.AtEndOfStream
    srtContents = rdFile.ReadLine
    If InStr(1, strContents, "success or error status: 0", 1) > 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

  12. #27

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,491
    Thank Post
    1,448
    Thanked 1,191 Times in 812 Posts
    Rep Power
    710
    It will definitely read each line one by one and check it, the reason only that line shows is that's the line that remains in memory.

    The last thing I can think to change in the code then is this line:

    Code:
    Change this:
    If InStr(1, strContents, "success or error status: 0", 1) > 0 Then
    
    To this:
    If InStr(1, strContents, "success or error status: 0", 0) > 0 Then

  13. #28

    Join Date
    Feb 2011
    Posts
    37
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Tried the change still no luck

  14. #29

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,491
    Thank Post
    1,448
    Thanked 1,191 Times in 812 Posts
    Rep Power
    710
    Quote Originally Posted by ICT_GUY View Post
    Ahem
    dir > myfile.txt

    Takes the output of dir and re-routes it to the file myfile.txt instead of outputting it to the screen.

    and can go down through the directory structure for you as well :-D

    dir /s /w /p

    This would list all the files and directories in the current directory and the sub directories after that, in wide format and one page at a time.

    dir /on

    List the files in alphabetical order by the names of the files.
    It doesn't check inside each text file for a certain string and add the results to your output though

  15. #30

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,491
    Thank Post
    1,448
    Thanked 1,191 Times in 812 Posts
    Rep Power
    710
    @NETKILLER - I'm sorry but I have to put my hands up and say I'm baffled the first version I posted worked fine for me, and with each tweak we've made throughout the thread it's continued to work for me, seems there's something odd going on at your end

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

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
  •