willem
willem

Reputation: 2717

Extracting all source code from visual studio express 2010 project into a single file?

How to extract all source code from a single c# project to a single file? Preferably not by copy-paste?

Upvotes: 4

Views: 1194

Answers (2)

Arthur
Arthur

Reputation: 8129

a very simple approach with the command line

for %f in (*.cs) do type %f >> result.txt

EDIT:

With recursion & file info

for /R %f in (*.cs) do echo ----- %f ----- >> result.txt & type %f >> result.txt

Upvotes: 3

aligray
aligray

Reputation: 2832

Simply pass in the path to the solution directory from the command line.

class Program
{
    static StringBuilder builder = new StringBuilder();

    static void Main(string[] args)
    {
        if (args.Length == 0)
            return;

        string directory = args[0];

        ProcessDirectories(directory);

        // Save file here
    }

    static void ProcessDirectories(string root)
    {
        ProcessDirectory(new DirectoryInfo(root));

        var subDirectories = Directory.GetDirectories(root);

        if (subDirectories.Length == 0)
            return;

        foreach (var subDirectory in subDirectories)
        {
            ProcessDirectories(subDirectory);
        }
    }

    static void ProcessDirectory(DirectoryInfo directory)
    {
        foreach (var file in directory.EnumerateFiles())
        {
            builder.AppendFormat("----- {0} -----", file.FullName);

            using (var reader = file.OpenText())
            {
                builder.AppendLine(reader.ReadToEnd());
            }
        }
    }
}

Hope it helps!

Upvotes: 1

Related Questions