Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace sqlRen
- {
- class Program
- {
- static void Main(string[] args)
- {
- string clArgument = Convert.ToString(args[0]); //Convert object in array args to string and store it in clArgument
- if (args.Contains("help") || args.Contains("/?") || args == null || args.Length == 0) //Help text
- {
- //Do something
- }
- else if (args.Contains("/ec")) //Help text
- {
- //Do another thing
- }
- else if (args.Count() > 1) //Is more than one argument given?
- {
- //Do something very different
- }
- else if (Regex.IsMatch(clArgument, @"^(?:[a-zA-Z]:(\|/)|\\|.(/|\))([^\/:*?<>]+(\|/){0,1})+$") && Directory.Exists(clArgument)) //Checking if entered argument is a valid Windows path using regex and checking if path exists
- {
- DirectoryInfo dicPre = new DirectoryInfo(clArgument); //Get directory
- FileInfo[] infosPre = dicPre.GetFiles(); //Get file informations from directory
- foreach (FileInfo file in infosPre)
- {
- File.Move(file.FullName, file.FullName.Replace("dbo.", "")); //remove the "dbo." prefix
- }
- Directory.CreateDirectory(clArgument + @"Functions");
- Directory.CreateDirectory(clArgument + @"Stored Procedures"); //Create desired subfolders
- Directory.CreateDirectory(clArgument + @"View");
- // vvv Moving files to desired subfolders vvv
- string[] patternUDFunctions = Directory.GetFiles(clArgument, "*.UserDefinedFunction.sql");
- foreach (string file in patternUDFunctions)
- {
- File.Move(file, clArgument + "Functions\" + Path.GetFileName(file));
- }
- string[] patternSP = Directory.GetFiles(clArgument, "*.StoredProcedure.sql");
- foreach (string file in patternSP)
- {
- File.Move(file, clArgument + "Stored Procedures\" + Path.GetFileName(file));
- }
- string[] patternV = Directory.GetFiles(clArgument, "*.View.sql");
- foreach (string file in patternV)
- {
- File.Move(file, clArgument + "View\" + Path.GetFileName(file));
- }
- // ^^^ Moving files to desired subfolders ^^^
- // vvv Deleting the filename-sufixes vvv
- DirectoryInfo dicUDF = new DirectoryInfo(clArgument + "Functions\");
- FileInfo[] infosUDF = dicUDF.GetFiles();
- foreach (FileInfo file in infosUDF)
- {
- File.Move(file.FullName, Regex.Replace(file.FullName, "(.UserDefinedFunction)", ""));
- }
- DirectoryInfo dicSP = new DirectoryInfo(clArgument + "Stored Procedures\");
- FileInfo[] infosSP = dicSP.GetFiles();
- foreach (FileInfo file in infosSP)
- {
- File.Move(file.FullName, Regex.Replace(file.FullName, "(.StoredProcedure)", ""));
- }
- DirectoryInfo dicV = new DirectoryInfo(clArgument + "View\");
- FileInfo[] infosV = dicV.GetFiles();
- foreach (FileInfo file in infosV)
- {
- File.Move(file.FullName, Regex.Replace(file.FullName, "(.View)", ""));
- }
- // ^^^ Deleting the filename-sufixes ^^^
- }
- else
- {
- //Yet another thing to do
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment