Skip to content

Instantly share code, notes, and snippets.

@roman-yagodin
Last active August 29, 2015 14:11
Show Gist options
  • Save roman-yagodin/992e0090dc8b251efb50 to your computer and use it in GitHub Desktop.
Save roman-yagodin/992e0090dc8b251efb50 to your computer and use it in GitHub Desktop.
Script to combine source files into single text file
#!/usr/bin/csharp
using System;
using System.IO;
using R7.Scripting;
class Combine
{
public void Run ()
{
Directory.SetCurrentDirectory("/home/redhound/Рабочий стол/Регистрация СДК/код/R7.HelpDesk/R7.HelpDesk");
var log = new Log("combine.log");
try
{
// provided by git ls-files
var files = File.ReadAllLines ("ls-files.txt");
var outfile = "single-file.txt";
var excludeExt = new [] { ".txt", ".md", ".png", ".jpg", ".gif", ".resx" };
var f = new FileStream (outfile, FileMode.Create, FileAccess.Write, FileShare.None);
var sw = new StreamWriter (f);
sw.AutoFlush = true;
foreach (string file in files)
{
var exclude = false;
var fileExt = Path.GetExtension(file).ToLowerInvariant ();
foreach (var ext in excludeExt)
if (fileExt == ext)
{
exclude = true;
break;
}
if (exclude) continue;
try
{
sw.WriteLine ();
sw.WriteLine ("Содержимое файла " + file + ":");
sw.WriteLine ();
var lines = File.ReadAllLines (file);
foreach (var line in lines)
sw.WriteLine (line);
Console.WriteLine (file);
}
catch (Exception ex)
{
log.WriteLine ("Error: " + ex.Message);
}
}
sw.Close();
f.Close();
}
catch (Exception ex)
{
log.WriteLine ("Error: " + ex.Message);
}
log.Close();
}
}
new Combine().Run ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment