Batch help
Results 1 to 2 of 2

Thread: Batch help

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    1

    Batch help

    Hi,
    I need help with making a batch file.
    It needs to:
    1. Search for a string in a text document.
    2. Make it become commented out.
    3. Temporarily replace it with a new string.
    4. Replace it with the old string.

    Or else it could do:
    1. Make a new command that does the same as another command.

    Thank you for any help provided,
    Rileyh

  2. #2
    Registered User CeeBee's Avatar
    Join Date
    Nov 2002
    Location
    USA
    Posts
    2,494
    Would be extremely difficult in a batch file.

    This could be easily done in a small program. Here is a sample in C#
    I've actually adapted one of my programs on the fly so it's not guaranteed to be typo-free...
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    
    namespace FixFile
    {
      class Program
      {
        static void Main(string[] args)
        {
          if (args.Length != 4)
          {
            Console.Write("Invalid parameters count " + args.Length.ToString() + ", expected 4");
            return;
          }
    
          string sInputFile;
          string sOutputFile;
          string sSearchString;
          string sCommentString;
          sInputFile = args[0];
          sOutputFile = args[1];
          sSearchString = args[2];
          sCommentString = args[3];
    
          TextReader reader;
          TextWriter writer;
          string sInputLine;
          string sOutputLine;
    
          try
          {
             writer=new StreamWriter(sOutputFile, false);
          }
          catch(Exception ex)
          {
            Console.WriteLine(ex.Message);
            return;
          }
    
          try
          {
            reader=new StreamReader(sInputFile);
          }
          catch(Exception ex)
          {
            Console.WriteLine(ex.Message);
            return;
          }
    
          while ((sInputLine = reader.ReadLine()) != null)
          {
            sOutputLine = sInputLine.Replace(sSearchString, sCommentString+sSearchString);
            writer.WriteLine(sOutputLine);
          }
          writer.Flush();
          writer.Close();
          reader.Close();
          Console.WriteLine("Program execution completed.");
        }
      }
    }
    Usage: FIXFILE.EXE source.txt destination.txt "search this string" "REM "
    Protected by Glock. Don't mess with me!

Similar Threads

  1. Batch File rookie with an idea
    By Niclo Iste in forum Programming And Web Design
    Replies: 27
    Last Post: October 16th, 2009, 09:50 AM
  2. Batch File Question
    By Low_Level_Owl in forum Tech-To-Tech
    Replies: 1
    Last Post: September 27th, 2006, 11:36 AM
  3. Batch File Hell...
    By Master Frodo UK in forum Windows XP
    Replies: 4
    Last Post: August 30th, 2006, 08:44 AM
  4. NTBackup, batch files, AT command and permissions
    By Underseer in forum Windows NT/2000
    Replies: 9
    Last Post: April 26th, 2001, 09:46 AM
  5. [RESOLVED] Windows 95/98 and batch files
    By Cesar_b in forum Windows 95/98/98SE/ME
    Replies: 2
    Last Post: June 22nd, 1999, 07:22 AM

Bookmarks

Posting Permissions

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