Script to search all files in specified folder for multiple string text values listed in a source file and output each match to one single results txt file

I have been searching high and low for this one.  I have a vbscript that can successfully perform the function if one file is listed.  It does a Wscript.echo on the results and if I run this via command using cscript, I can output to a text file
that way.  However, I cannot seem to get it to work properly if I want it to search ALL the files in the folder.  At one point, I was able to have it create the output file and appear as if it worked, but it never showed any results when the script
was executed and folder was scanned.  So I am going back to the drawing board and starting from the beginning.
I also have a txt file that contains the list of string text entries I would like it to search for.  Just for testing, I placed 4 lines of sample text and one single matching text in various target files and nothing comes back.  The current script
I use for each file has been executed with a few hundred string text lines I want it to search against to well over one thousand.  It might take awhile, but it works every time. The purpose is to let this run against various log files in a folder and
let it search.  There is no deleting, moving, changing of either the target folder/files to run against, nor of the file that contains the strings to search for.  It is a search (read) only function, going thru the entire contents of the folder and
when done, performs the loop function and onto the next file to repeat the process until all files are searched.  When completed, instead of running a cscript to execute the script and outputting the results to text, I am trying to create that as part
of the overall script.  Saving yet another step for me to do.
My current script is set to append to the same results file and will echo [name of file I am searching]:  No errors found.  Otherwise, the
output shows the filename and the string text that matched.  Because the results append to it, I can only run the script against each file separately or create individual output names.  I would rather not do that if I could include it all in one.
 This would also free me from babysitting it and running each file script separately upon the other's completion.  I can continue with my job and come back later and view the completed report all in one.  So
if I could perform this on an entire folder, then I would want the entries to include the filename, the line number that the match occurred on in that file and the string text that was matched (each occurrence).  I don't want the entire line to be listed
where the error was, just the match itself.
Example:  (In the event this doesn't display correctly below, each match, it's corresponding filename and line number all go together on the same line.  It somehow posted the example jumbled when I listed it) 
File1.txt Line 54 
Job terminated unexpectedly
 File1.txt Line 58 Process not completed
File1.txt
Line 101 User input not provided
File1.txt
Line 105  Process not completed
File2.txt
No errors found
File3.txt
Line 35 No tape media found
File3.txt
Line 156 Bad surface media
File3.txt Line 188
Process terminated
Those are just random fake examples for this post.
This allows me to perform analysis on a set of files for various projects I am doing.  Later on, when the entire search is completed, I can go back to the results file and look and see what files had items I wish to follow up on.  Therefore, the
line number that each match was found on will allow me to see the big picture of what was going on when the entry was logged.
I actually import the results file into a spreadsheet, where further information is stored regarding each individual text string I am using.  Very useful.
If you know how I can successfully achieve this in one script, please share.  I have seen plenty of posts out there where people have requested all different aspects of it, but I have yet to see it all put together in one and work successfully.
Thanks for helping.

I'm sorry.  I was so consumed in locating the issue that I completely overlooked posting what exactly I was needing  help with.   I did have one created, but I came across one that seemed more organized than what I originally created.  Later
on I would learn that I had an error in log location on my original script and therefore thought it wasn't working properly.  Now that I am thinking that I am pretty close to achieving what I want with this one, I am just going to stick with it.
However, I could still use help on it.  I am not sure what I did not set correctly or perhaps overlooking as a typing error that my very last line of this throws an "Expected Statement" error.  If I end with End, then it still gives same
results.
So to give credit where I located this:
http://vbscriptwmi.uw.hu/ch12lev1sec7.html
I then adjusted it for what I was doing.
What this does does is it searches thru log files in a directory you specify when prompted.  It looks for words that are contained in another file; objFile2, and outputs the results of all matching words in each of those log files to another file:  errors.log
Once all files are scanned to the end, the objects are closed and then a message is echoed letting you know (whether there errors found or not), so you know the script has been completed.
What I had hoped to achieve was an output to the errors.log (when matches were found) the file name, the line number that match was located on in that file and what was the actual string text (not the whole line) that matched.  That way, I can go directly
to each instance for particular events if further analysis is needed later on.
So I could use help on what statement should I be closing this with.  What event, events or error did I overlook that I keep getting prompted for that.  Any help would be appreciated.
Option Explicit
'Prompt user for the log file they want to search
Dim varLogPath
varLogPath = InputBox("Enter the complete path of the logs folder.")
'Create filesystem object
Dim oFSO
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
'Creates the output file that will contain errors found during search
Dim oTSOut
Set oTSOut = oFSO.CreateTextFile("c:\Scripts\errors.log")
'Loop through each file in the folder
Dim oFile, varFoundNone
VarFoundNone = True
For Each oFile In oFSO.GetFolder(varLogPath).Files
    'Verifies files scanned are log files
    If LCase(Right(oFile.Name,3)) = "log" Then
        'Open the log file
        Dim oTS
        oTS = oFSO.OpenTextFile(oFile.Path)
        'Sets the file log that contains error list to look for
        Dim oFile2
        Set oFile2 = oFSO.OpenTextFile("c:\Scripts\livescan\lserrors.txt", ForReading)
        'Begin reading each line of the textstream
        Dim varLine
        Do Until oTS.AtEndOfStream
            varLine = oTS.ReadLine
            Set objRegEx = CreateObject("VBScript.RegExp")
            objRegEx.Global = True  
            Dim colMatches, strName, strText
            Do Until oErrors.AtEndOfStream
                strName = oFile2.ReadLine
                objRegEx.Pattern = ".{0,}" & strName & ".{0,}\n"
                Set colMatches = objRegEx.Execute(varLine)  
                If colMatches.Count > 0 Then
                    For Each strMatch in colMatches 
                        strText = strText & strMatch.Value
                        WScript.Echo "Errors found."
                        oTSOut.WriteLine oFile.Name, varLine.Line, varLine
                        VarFoundNone = False
                    Next
                End If
            Loop
            oTS.Close
            oFile2.Close
            oTSOut.Close
            Exit Do
            If VarFoundNone = True Then
                WScript.Echo "No errors found."
            Else
                WScript.Echo "Errors found.  Check logfile for more info."
            End If
    End if

Similar Messages

  • Deleteing folder for multiple users

    Good morning all -
    As most people would admit, I am terrible at scripting in any form.  In short, I need assistance with a dummy proof script to delete the contents of a folder for multiple (150+) users, without  having to touch each users profile.  I would
    prefer to be able to execute the script when needed.  This won't be listed as a scheduled task or setup as a netlogon. The path is as follows:
    C:\Users\michael.jannise.ctr\NS5\tmp
    It can either be set to delete the tmp folder entirely, or just the contents of the folder.  Which ever is easier. 
    I would greatly appreciate any assistance provided!
    Regards,
    Michael

    I was going to warn you but this is more fun.
    Understanding Windows and the Windows file system is always a big problem for non-technicians.
    Learning this technology requires some time for testing things until you understand how they work. You really cannot learn this by asking people on the Internet to give you answers.
    The command, as posted. removes only the "tmp" folder contents. How to make that clear is not clear. It needs to be tried. THe safe way yo do thisis to make a parallel structure and test that.
    ¯\_(ツ)_/¯
    Well, I can play the game!  :)  I know I should spend the time working with this type of technology but, I would not execute it day to day and would most likely still make mistakes. 
    I am extremely grateful for people like yourselves who are willing to share the knowledge!

  • When looking at my "About This Mac" it says that I have 60gb of space left on my hard drive, but when I go into finder to find all of these files there is not 300gb worth in anything I search, even searching, "All files on the Mac". Help!?

    When looking at my "About This Mac" it says that I have 60gb of space left on my hard drive, but when I go into finder to find all of these files there is not 300gb worth in anything I search, even searching, "All files on the Mac". Help!?
    It says I have over 150 gigs of video on my hard drive. But I have gone through and deleted almost all of what shows up, still it says there is roughly the same amount on the hard drive. Where are these files? I want to delete them so I can have my hard drive clear.
    Thanks for your help guys!

    Quote from the article.
    Time Machine in OS X Lion includes a new feature called "local snapshots" that keeps copies of files you create, modify or delete on your internal disk. Local snapshots compliment regular Time Machine backups (that are stored on your external disk or Time Capsule) giving you a "safety net" for times when you might be away from your external backup disk or Time Capsule and accidentally delete a file.
    So what makes a notebook any different then a desktop, other then with a desktop you might have your tm backup drive connected all the time.
    The object here is to not indiscriminately delete files you need or want to keep. I personally have never deleted a file I wanted to keep.
    In essence a backup is for catastrophic failure of your system. So it can be restored once that failure has been fixed. Not because you go in willy nilly and start deleting files.

  • Search for a String in a list of files

    Could anyone please send me a java sample code which searches for a string from a list of files and returns me the filename and the line in which the Search String was found ?
    Thanks in advance
    RR

    Simple solution would be -
    1. Traverse a directory for each file.
    2. Read each file using Buffered Reader.
    3. Use readLine() method to read a line.
    4. Use String.indexOf to see if the data which you are looking for is there in the line or not.
    5. If its there then store the line number and file name.
    6. When the loop will end you will have list of file name and line number where the data which you are looking for is present.

  • App-V PowerShell: Script to Query XenApp Servers for App-V Publishing Errors and Output an Excel Document with the Results

    Please Vote if you find this to be helpful!
    App-V PowerShell:  Script to Query XenApp Servers for App-V Publishing Errors and Output an Excel Document with the Results
    Just posted this to the wiki:
    http://social.technet.microsoft.com/wiki/contents/articles/25323.app-v-powershell-script-to-query-xenapp-servers-for-app-v-publishing-errors-and-output-an-excel-document-with-the-results.aspx

    Hi petro_jemes,
    Just a little claritification, you need to add the value to the variable "[string]$ou", and also change the language in the variable "$emailbody" in the function "Get-ADUserPasswordExpirationDate".
    I hope this helps.

  • Script to set all files in a folder to "Read and Write" permissions? Please

    In advance my most abject apologies for posting such a simple question. I couldn't script my way out of a paper bag, and searching and googling have failed, no doubt because I don't even have the proper keywords. :-/
    The script I need is so simple that it most likely exists somewhere already. Whenever I copy image files from a DVD-ROM or CD-ROM burned on a Windows laptop to my desktop Mac, the files and folders therein are "Read Only" on my Mac. If there are many files in the folder, it's very easy to Select All and do a Get Info on multiple items, so I can rectify the situation by changing the whole set in a single step. But if I have ten files or less in a folder, each file opens an Info dialog box and that can become very tedious when I have scores of folders with nine or so files in each.
    Any guidance will be much appreciated.
    Message was edited by: Ramón G Castañeda

    You can attach a folder action to your destination folder, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on adding folder items to ThisFolder after receiving AddedItems
    repeat with AnItem in AddedItems
    tell application "Finder" to set owner privileges of AnItem to read write
    -- tell application "Finder" to set everyones privileges of AnItem to read write
    end repeat
    end adding folder items to
    </pre>
    ... but you can also use the Inspector (option-command-i) to get a single info window for multiple items.

  • Creating a public folder for multiple computers

    I am putting together my home media center. We have a number of computers and would like to use one central folder on our server to house all our media. Is there a way to have each individual computer store all music in that folder, and point to that same folder to play music? I just want to make sure I set it up correctly. currently I am able to get the second computer to recognize a share folder on another computer, but will not recognize the music in the folder.

    Dear Anni,
    For creating folder stucture u hv to use easy DMS if u r using Easy DMS.
    if U working on R3;
    thn goto DMS
    Use tcode cv03n, open the document for which you want create folder.
    goto document browser tab for perticular document, here u can create publeic as well as private folder and add documents as per your reqt.
    In this u can also give authorisation of folder as per reqt.
    If u hv any further query, please revert back.
    give points if u find above information useful
    Pramod

  • [Solved] When I open multiple Firefox windows an orange pull down tab appears and I cannot exit from any single window. I have to exit all of the Firefox windows to close one.

    I like to open several Firefox windows when I am browsing the internet. Since mi reinstall of windows XP with sp3 I installed Firefox 5.0.1. Now when I open multiple windows they kind of window in a window and I get this orange pull down menu. I can no longer close any one single window. I click the lower of the two top right X's to close the window and all the tabs in that window, but nothing happens. I also don't like the look and feel of the orange pull down menu

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    In Firefox 4 and later [http://kb.mozillazine.org/Safe_mode Safe mode] disables extensions and disables hardware acceleration.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    If disabling hardware acceleration works then check if there is an update available for your graphics display driver.
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • Can I convert each playlist into one single mp3 file

    I have had great success creating and burning a playlist to a CD however I'd really prefer to save an ENTIRE playlist of about 20 songs as a SINGLE MP3 file.  I can then I burn each file (composed of songs in a playlist)  to a CD and have a nice set of organized music set/PLAYLISTS to listen to.  I stated my question in this manner because I've seen many similar questions but they are not what I am asking. I am using WIndows 7
    What I have tried:
    1.) ...selecting the group of songs within the playlist and exporting as an MU3.  My results:  It created an MU3 file that played for less than 1 second when played in anything other than itunes.  In itunes it opened as the same playist I began with
    2.) ...consolidating the files (the goal was to consolidate into one MP3 file) but once I selected the consolidate option I could not find that file under itunes Media which is the location where itunes says it would be stored.
    3.) ..converting to MP3       Result: It just converted each individual file to MP3 format and NOT the entire list as a SINGLE MP3 file.
    Does anyone know if there is a way to accomplish this?
    Thanks in advance
    D

    Sorry to disappoint you, Chris... but I don't "take their product". Someone WHO WORKS FOR THEM "gives it to me". There's a MAJOR DIFFERENCE between someone handing you something that's theirs to hand you... and stealing it.
    In 2006 I saw Sara Evans "perform" in Tucson. She flew on her congressional (then) husband's private plane from Portland to Orange County, refueled and flew to Tucson, where she got into a limo, and rode to the show. She got out of the limo, went straight backstage, I saw someone hand her a Dr. Pepper, which she opened, took a sip out of, and then went out on the stage as the headline act for the evening. She sang six (6) songs in twenty-three (23) minutes, walked offstage, did no encore, and got back in the limo, which whisked her back to the waiting jet to fly home.
    The station manager of the radio station that sponsored the concert, later told me that she was paid $125,000 for that twenty-three minutes. Even he felt like the station didn't get their money's worth. The promoter paid for the jet fuel and her pilots' salaries.
    In 2009, I went out to Phil Vassar's "motor coach" after a show, which is basically a house on wheels. He showed two friends and I the "studio" in the middle of this converted bus, where he can record new tracks and send them straight to the record company via satelite, for their final editing. The front has a full kitchen & living room and a 50" flat screen TV with a massive audio system. HE owns the whole thing, and when he doesn't feel like riding, he has a private plane of his own that will pick him up wherever they can land and fly him to the next show.  His promo guy gave each of us a copy of every CD he's ever released before we left.
    I have no problem with people making money for their work. But I've seen just how much is given away in the music industry, and I'm not going to refuse things offered to me because someone with a private jet and limo, getting $6000 a minute, or with a half million dollar "rolling house" isn't getting paid for the things their own people are handing out in bulk.

  • Why won't my script work on all files in the folder?

    Hi, below is a script I hobbled together from various sources using the search function on this forum. It is supposed to change hyphens to en-dashes in a ai files in a folder. However, when I run it, it only works on one file. After it makes the change and closes the first file, it stops. Can anyone help me troubleshoot and fix the problem?
    var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
    sourceFolder = Folder.selectDialog;
    if ( sourceFolder != null )
        files = new Array();
        fileType = "*.ai";
        files = sourceFolder.getFiles( fileType );
        if ( files.length > 0 )
            destFolder = sourceFolder;
           for ( i = 0; i < files.length; i++ )
                sourceDoc = app.open(files[i]); // returns the document object
    var active_doc = app.activeDocument;
    var search_string = '-';
    var replace_string = "\u2013";
    var text_frames = active_doc.textFrames;
    if (text_frames.length > 0)
        for (var i = 0 ; i < text_frames.length; i++)
              var this_text_frame = text_frames[i];
               var new_string = this_text_frame.contents.replace(search_string, replace_string);
               if (new_string != this_text_frame.contents)
                        this_text_frame.contents = new_string;
             sourceDoc.save();
             sourceDoc.close();

    no easy way as you may wish, but not as difficult either. For eps files, you have to use SaveAs() method,
    if ai - do save
    if eps - do saveAs
    here's a sample from the Documentation, or search the forum for other samples
    // Exports current document to destFile as an EPS file with specified
    // options, destFile contains the full path including the file name
    function exportFileAsEPS (destFile) {
    var newFile = new File(destFile);
    var saveDoc;
    if ( app.documents.length == 0 )
    saveDoc = app.documents.add();
    else
    saveDoc = app.activeDocument;
    var saveOpts = new EPSSaveOptions();
    saveOpts.cmykPostScript = true;
    saveOpts.embedAllFonts = true;
    saveDoc.saveAs( newFile, saveOpts );

  • How to search all files in folders/subfolders for one or more strings?

    I have a list of files (full path and file name) in Column D of my worksheet.  I'm trying to figure out how to run some code to open each file in this array (starting on D14 and going down), search for one or more strings, and then put an "X"
    in Column I, in the same row as the file name.
    How can I do that?
    I experimented with a few samples of code.  It seems pretty easy to do it in one folder, but not all sub folders.  The folder/subfolder is setup a specific way for a specific purpose.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Below is an example that allow you to search a directory and its subdirs txt files(you can change this), read its lines and search for specific word:
    using System;
    using System.IO;
    using System.Linq;
    class Program
    static void Main(string[] args)
    try
    var files = from file in Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories)
    from line in File.ReadLines(file)
    where line.Contains("Microsoft")
    select new
    File = file,
    Line = line
    foreach (var f in files)
    Console.WriteLine("{0}\t{1}", f.File, f.Line);
    Console.WriteLine("{0} files found.", files.Count().ToString());
    catch (UnauthorizedAccessException UAEx)
    Console.WriteLine(UAEx.Message);
    catch (PathTooLongException PathEx)
    Console.WriteLine(PathEx.Message);
    https://msdn.microsoft.com/en-us/library/dd997370%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    Fouad Roumieh

  • Lost safari can see it is in my icloud but have searched all files and it is not there how do I get it back?

    Lost Safari looked Ina all the files in icloud I can see that it is used by icloud but can't access it.  How do I get it back?

    You cannot lose Safari as it is part of iOS.  It's on your iPad somewhere.
    Here are some choices how to proceed:
    1.  Go to your home screen, swipe from left to right, and type "Safari" in the search screen.  You will find a link to take you there.
    2.  Go to Settings > General > Reset > Reset Home Screen Layout

  • Give a handmake function to search all files in the directory.

    To scan drive, folder, ets.
    I maked this, but my function is big bleep, a devil will break his legs here.
    Need small workable solution.
    Attachments:
    function.txt ‏7 KB

    Sergey,
    Here is an example file which looks through every file in a directory.http://zone.ni.com/devzone/cda/epd/p/id/2157
    It should save you some time if you are having issues with your code. 
    Regards,
    Kyle Mozdzyn
    Applications Engineering
    National Instruments
    Regards,
    Kyle M.
    Applications Engineering
    National Instruments

  • How do I use one downloads folder for multiple users?

    I recently added my girlfriend a profile in my Imac. We both have seperate Profiles and logins however I would like to find out, if the the Downloads folder can be used by both profiles. I found that each profile has their own Downloads folder, and goes to their own locations.
    I would like to find out, if its possible to re-direct my downloaded files as well as her downloaded files into just ONE "Downloads" folder. The default destination of the downloads folder would be /users/girlfriend(name of girlfriend). I want to change it to /users/(me) so that all downloads would just go to one folder.
    Thanks in advance!

    Direct your downloads to Users-Shared

  • One iTunes media folder for multiple users

    Hi there,
    I'm having trouble getting iTunes 9.0.3 to let me share one media folder across two users. I want to be able to share and update the contents of the media folder from either user account. I had this going before I updated thanks to another discussions post and a little program called BatCHmod, but now it doesn't seem to be working. Not only that, iTunes can't find some of my apps. Help?
    It would also be great to be able to do the same with iPhoto.
    Thanks.

    Welcome to Apple Discussions !
    There's no easy answer for this one. Even the best options still require ongoing maintenance to keep things aligned.
    The Consolidate command, unlike your expectations, only examines the current files known to iTunes and copies/reorganizes them into the "Music Location" setting. It does reattach files that were already moved to another location.
    Generally speaking, the best option is to work from the computer with the largest/most complete set of music, consolidate it to the new drive, and then use a manual method or recreate the library on other computers using the network location. The "manual" method involves manually editing the "iTunes Music Library.XML" file on the computer to replace the old file location string with the new network location. As long as iTunes was maintaining files in its preferred location (drive:\...\iTunes Music\artist\album\song) this method can magically make the other iTunes' look to the new location for the file.
    As for the "missing file" entries, here's a slightly automated cleanup routine.
    * select all the files in the iTunes library list
    * Get Info
    * set BPM to 99 (presumes you don't rely on the BPM field for real data), missing files won't be updated (of course)
    * after that completes add BPM to the Library view (ctrl-j or "view options") and sort the library by BPM
    * all the missing files are now grouped together so you can easily delete their entries.
    As for after all computers are using the network drive...
    When a user adds music to their library, other users will not see that new entry. You have to manually drag those new files into the iTunes library on the other computers.

Maybe you are looking for