-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRegexToLowerApp.cs
More file actions
67 lines (53 loc) · 2.38 KB
/
RegexToLowerApp.cs
File metadata and controls
67 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// /*
// * The attached / following is part of SharpMap.Data.Providers.Kml
// * SharpMap.Data.Providers.Kml is free software © 2008 Newgrove Consultants Limited,
// * www.newgrove.com; you can redistribute it and/or modify it under the terms
// * of the current GNU Lesser General Public License (LGPL) as published by and
// * available from the Free Software Foundation, Inc.,
// * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA: http://fsf.org/
// * This program is distributed without any warranty;
// * without even the implied warranty of merchantability or fitness for purpose.
// * See the GNU Lesser General Public License for the full details.
// *
// * Author: John Diss 2009
// *
// */
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace RegexSource
{
internal class RegexToLowerApp
{
public static void Run()
{
Console.WriteLine(
@"This app will parse a directory of files and replace patterns of text with another pattern lowered eg.
using search pattern (_[A-Z)
replace pattern \0
the string ""_Address"" is transformed to ""_address""
");
Console.WriteLine("Please Enter the Regex Search Pattern");
string search = Console.ReadLine();
Console.WriteLine("Please Enter the Regex Replace Pattern");
string replace = Console.ReadLine();
Regex r = new Regex(search);
Console.WriteLine("Please enter the path to the directory.");
string path = Console.ReadLine();
Console.WriteLine("Please enter the file search pattern");
string pattern = Console.ReadLine();
DirectoryInfo inf = new DirectoryInfo(path);
FileInfo[] files = inf.GetFiles(pattern);
string exportPath = Path.Combine(path, "Regexed");
if (!Directory.Exists(exportPath))
Directory.CreateDirectory(exportPath);
Regex r2 = new Regex(replace);
foreach (FileInfo info in files)
{
string txt = File.ReadAllText(info.FullName);
string regexed = r.Replace(txt, a => r2.Replace(a.ToString(), replace).ToLower());
File.WriteAllText(Path.Combine(exportPath, info.Name), regexed);
}
}
}
}