-
October 8th, 2011, 10:55 PM
#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
-
October 11th, 2011, 12:09 PM
#2
Registered User
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
-
By Niclo Iste in forum Programming And Web Design
Replies: 27
Last Post: October 16th, 2009, 09:50 AM
-
By Low_Level_Owl in forum Tech-To-Tech
Replies: 1
Last Post: September 27th, 2006, 11:36 AM
-
By Master Frodo UK in forum Windows XP
Replies: 4
Last Post: August 30th, 2006, 08:44 AM
-
By Underseer in forum Windows NT/2000
Replies: 9
Last Post: April 26th, 2001, 09:46 AM
-
By Cesar_b in forum Windows 95/98/98SE/ME
Replies: 2
Last Post: June 22nd, 1999, 07:22 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks