NOTE:- COPY TEXT FILE'S FOLDER IN C DRIVE & NAMED IT AS 'DietNutrition'.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace TextToHtm
{
class Program
{
static void Main(string[] args)
{
DirSearch(@"C:\DietNutrition");
}
public static void DirSearch(string sDir)
{
try
{
List<string> ttt = new List<string>();
ttt.Add("<html><head><title>Index</title></head><body><br/>");
foreach (string f in Directory.GetFiles(sDir))
{
SearchFileAndAddToObject(f);
ttt.Add("<a href=" + f.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", "") + ">" + f.Replace(".txt", "").Replace("DietNutrition", "DietNutritionHtm").Replace(@"C:\DietNutritionHtm\","")+"</a><br/>");
}
ttt.Add("</body></html>");
string f1 = @"C:\DietNutritionHtm\Index.html";
// File.Create(f1.Replace(" ", ""));
File.WriteAllLines(f1.Replace(" ", ""), ttt.ToArray(), Encoding.GetEncoding("Windows-1252"));
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
SearchFileAndAddToObject(f);
}
DirSearch(d);
}
}
catch (System.Exception exception)
{
Console.WriteLine(exception.Message);
}
Console.ReadLine();
}
public static void SearchFileAndAddToObject(string filename)
{
string[] fileByLines = File.ReadAllLines(filename, Encoding.GetEncoding("Windows-1252"));
List<string> tt = new List<string>();
tt.Add("<html><head><title>");
foreach (string line in fileByLines)
{
string Newline;
if(line.Contains("["))
{
Newline = "<title>" + line.Substring(0, line.IndexOf("[")).Replace("Œ", "") + @"</title></head><body style=""background-image:url(qhc_body.jpg)""><table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""0""><tr><td align=""center""><img src=""logo1.png"" alt=""Logo"" /></td></tr><tr><td>";
}
else
Newline = line.Replace("Œ", "<b><u style=\"Color:660066\"><hr>") + "<b> </u><br/>";
tt.Add(Newline);
Newline = Newline.Replace("•", "*").Replace("-", "*");
}
tt.Add("</td></tr></table></body></html>");
Directory.CreateDirectory(@"C:\DietNutritionHtm");
// File.Create(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", ""));
File.WriteAllLines(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ",""), tt.ToArray(), Encoding.GetEncoding("Windows-1252"));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace TextToHtm
{
class Program
{
static void Main(string[] args)
{
DirSearch(@"C:\DietNutrition");
}
public static void DirSearch(string sDir)
{
try
{
List<string> ttt = new List<string>();
ttt.Add("<html><head><title>Index</title></head><body><br/>");
foreach (string f in Directory.GetFiles(sDir))
{
SearchFileAndAddToObject(f);
ttt.Add("<a href=" + f.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", "") + ">" + f.Replace(".txt", "").Replace("DietNutrition", "DietNutritionHtm").Replace(@"C:\DietNutritionHtm\","")+"</a><br/>");
}
ttt.Add("</body></html>");
string f1 = @"C:\DietNutritionHtm\Index.html";
// File.Create(f1.Replace(" ", ""));
File.WriteAllLines(f1.Replace(" ", ""), ttt.ToArray(), Encoding.GetEncoding("Windows-1252"));
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
SearchFileAndAddToObject(f);
}
DirSearch(d);
}
}
catch (System.Exception exception)
{
Console.WriteLine(exception.Message);
}
Console.ReadLine();
}
public static void SearchFileAndAddToObject(string filename)
{
string[] fileByLines = File.ReadAllLines(filename, Encoding.GetEncoding("Windows-1252"));
List<string> tt = new List<string>();
tt.Add("<html><head><title>");
foreach (string line in fileByLines)
{
string Newline;
if(line.Contains("["))
{
Newline = "<title>" + line.Substring(0, line.IndexOf("[")).Replace("Œ", "") + @"</title></head><body style=""background-image:url(qhc_body.jpg)""><table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""0""><tr><td align=""center""><img src=""logo1.png"" alt=""Logo"" /></td></tr><tr><td>";
}
else
Newline = line.Replace("Œ", "<b><u style=\"Color:660066\"><hr>") + "<b> </u><br/>";
tt.Add(Newline);
Newline = Newline.Replace("•", "*").Replace("-", "*");
}
tt.Add("</td></tr></table></body></html>");
Directory.CreateDirectory(@"C:\DietNutritionHtm");
// File.Create(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ", ""));
File.WriteAllLines(filename.Replace(".txt", ".html").Replace("DietNutrition", "DietNutritionHtm").Replace(" ",""), tt.ToArray(), Encoding.GetEncoding("Windows-1252"));
}
}
}
No comments:
Post a Comment