Reputation: 735
After using an automatic comment header application, I found that it deleted the last return before the code started. This means that all of my files in the solution now look like this:
//-----------------------------------------------------------------------------
// File Name: Mapper.cs
// Creation Date: 13/02/2013
// Author: person
//-----------------------------------------------------------------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
I have a couple of hundred of files I now need to fix and my source control went away (Was on an EC2 Micro that lapsed). I seem to have encountered a series of unfortunate events here. Is there a macro, or something similar, that can help me get out of this bind?
Upvotes: 1
Views: 108
Reputation: 157018
In Visual Studio you can do a replace all with wild cards enabling you to insert the line break. I don't have the IDE available now but it should be something like this:
Search in all files in the project for this using wildcards:
---using
Replace this by:
---\nusing
Or as Kirk suggested, use regex.
Search for:
---.*
Replace by:
---\n\1
Upvotes: 3
Reputation: 4460
Edit > Find and Replace > Find in Files
. Find options
group box and enable
Use Regular Expressions
.Find what:
drop down paste -using System;
Replace with:
drop down paste -\rusing System;
Look in:
drop down use Entire Solution
.*.cs
to the Look at these file types:
drop down.Try your search with the Find Next
and Replace
options. If things look good, then pray to the Visual Studio Gods and click the Replace All
button.
Upvotes: 1
Reputation: 216303
A different approach from using the IDE, you could start your LinqPAD and then run this code (well a backup before is not to forget)
void Main()
{
string yourRootSolutionPath = @"D:\temp";
foreach(string s in Directory.EnumerateFiles(yourRootSolutionPath, "*.cs", SearchOption.AllDirectories))
{
string[] lines = File.ReadAllLines(s);
for(int x = 0; x < lines.Length; x++)
{
int pos = lines[x].IndexOf("---using");
if(pos > 0)
{
lines[x] = lines[x].Substring(0, pos+3) + Environment.NewLine + lines[x].Substring(pos+3);
File.WriteAllLines(s, lines);
break;
}
}
}
}
Upvotes: 1