none
Name an output file with the filename of the file searched? RRS feed

  • Question

  • Hi Scripting guy!

    I have a script that searches a certain pattern at a file. I have successfully done this reading through some of the tutorials here. My question is how can I be able to do this routine if my file to be read is a number of files within a folder with the last part of the path represents the file name to be searched until all the log file has been read then the output loadfile and LFdir in a notepad with the name of the file that it searched ?

    the folder: C:temp\LOGS\ contains several .log files --> t01-uflx.log ; t02-uflx.log ; t03-uflx.log ; t04-uflx.log etc

    Const ForReading = 1
    'set up loadfile to be read
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:temp\LOGS\t01-uflx.log")

    strTargetText = objFile.ReadAll
    objFile.Close

    Set objRegEx = CreateObject("VBScript.RegExp")
    objRegEx.Global = False 'was True | if false will stop at first match of search string 

    'set file including search criteria for preparation for the extraction
        strName = "Program Load"
        objRegEx.Pattern = ".{0,}" & strName & ".{0,}\n"
        Set colMatches = objRegEx.Execute(strTargetText)  

        If colMatches.Count > 0 Then
      For Each strMatch in colMatches 
               strText = strText & strMatch.Value
               mylen = len(strMatch)
               count = mylen - 31
               loadfile =  Mid(strMatch.Value,32,count - 2)
               WScript.Echo loadfile
               next
              else
          End If

        strName = "Device Dir"
        objRegEx.Pattern = ".{0,}" & strName & ".{0,}\n"
        Set colMatches = objRegEx.Execute(strTargetText)  

        If colMatches.Count > 0 Then
      For Each strMatch in colMatches 
               strText = strText & strMatch.Value
               mylen = len(strMatch)
               count = mylen - 31
               LFdir =  Mid(strMatch.Value,32,count - 2 )
               next
              else
        End If

    objFile.Close

                                                            
    • Edited by Mckulet Thursday, February 5, 2015 12:28 PM wrong question per admin
    Thursday, February 5, 2015 9:50 AM

Answers

  • i was able to complete this task already with below just incase someone encounters the same question i Had

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "C:\LOGS" ' folder that contains the files to be read

    Set objFolder = objFSO.GetFolder(objStartFolder)

    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    Net = split (objFile.name,".") ' so I can only get the base name
        raw = Net(0) 'assigned to a variable raw so I can use in my code above.
       
        Wscript.Echo raw
    Next

    Sunday, February 8, 2015 4:32 AM

All replies

  • You will need to hire a consultant to do this for you.  We can only answer basic questions.  This is not a free scripting or consulting forum.

    If you want to do this yourself there are learning materials linked at the top of this page.  Post back if you have a specific question.


    ¯\_(ツ)_/¯

    Thursday, February 5, 2015 10:32 AM
  • Hi JRV thanks for the notice... I have edited my query accordingly...
    Thursday, February 5, 2015 12:29 PM
  • i was able to complete this task already with below just incase someone encounters the same question i Had

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "C:\LOGS" ' folder that contains the files to be read

    Set objFolder = objFSO.GetFolder(objStartFolder)

    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    Net = split (objFile.name,".") ' so I can only get the base name
        raw = Net(0) 'assigned to a variable raw so I can use in my code above.
       
        Wscript.Echo raw
    Next

    Sunday, February 8, 2015 4:32 AM
  • Please read this instructions on the package:

    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set folder = fso.GetFolder("C:\logs")
    For Each file in folder.Files   
        Wscript.Echo split(file.shortname,".")(0)
    Next 

    No user serviceable parts inside.

    Of course this wasn't what you asked in your original question.


    ¯\_(ツ)_/¯


    • Edited by jrv Sunday, February 8, 2015 5:11 AM
    Sunday, February 8, 2015 5:10 AM
  • HI JRV yes i edited it accordingly upon your response. I also mentioned that above.
    Sunday, February 8, 2015 11:16 AM