Guest User

Untitled

a guest
Mar 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace sqlRen
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string clArgument = Convert.ToString(args[0]); //Convert object in array args to string and store it in clArgument
  12.  
  13. if (args.Contains("help") || args.Contains("/?") || args == null || args.Length == 0) //Help text
  14. {
  15. //Do something
  16. }
  17.  
  18. else if (args.Contains("/ec")) //Help text
  19. {
  20. //Do another thing
  21. }
  22.  
  23. else if (args.Count() > 1) //Is more than one argument given?
  24. {
  25. //Do something very different
  26. }
  27.  
  28. 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
  29. {
  30. DirectoryInfo dicPre = new DirectoryInfo(clArgument); //Get directory
  31. FileInfo[] infosPre = dicPre.GetFiles(); //Get file informations from directory
  32. foreach (FileInfo file in infosPre)
  33. {
  34. File.Move(file.FullName, file.FullName.Replace("dbo.", "")); //remove the "dbo." prefix
  35. }
  36.  
  37. Directory.CreateDirectory(clArgument + @"Functions");
  38. Directory.CreateDirectory(clArgument + @"Stored Procedures"); //Create desired subfolders
  39. Directory.CreateDirectory(clArgument + @"View");
  40.  
  41. // vvv Moving files to desired subfolders vvv
  42.  
  43. string[] patternUDFunctions = Directory.GetFiles(clArgument, "*.UserDefinedFunction.sql");
  44. foreach (string file in patternUDFunctions)
  45. {
  46. File.Move(file, clArgument + "Functions\" + Path.GetFileName(file));
  47. }
  48.  
  49. string[] patternSP = Directory.GetFiles(clArgument, "*.StoredProcedure.sql");
  50. foreach (string file in patternSP)
  51. {
  52. File.Move(file, clArgument + "Stored Procedures\" + Path.GetFileName(file));
  53. }
  54.  
  55. string[] patternV = Directory.GetFiles(clArgument, "*.View.sql");
  56. foreach (string file in patternV)
  57. {
  58. File.Move(file, clArgument + "View\" + Path.GetFileName(file));
  59. }
  60.  
  61. // ^^^ Moving files to desired subfolders ^^^
  62.  
  63. // vvv Deleting the filename-sufixes vvv
  64. DirectoryInfo dicUDF = new DirectoryInfo(clArgument + "Functions\");
  65. FileInfo[] infosUDF = dicUDF.GetFiles();
  66. foreach (FileInfo file in infosUDF)
  67. {
  68. File.Move(file.FullName, Regex.Replace(file.FullName, "(.UserDefinedFunction)", ""));
  69. }
  70.  
  71. DirectoryInfo dicSP = new DirectoryInfo(clArgument + "Stored Procedures\");
  72. FileInfo[] infosSP = dicSP.GetFiles();
  73. foreach (FileInfo file in infosSP)
  74. {
  75. File.Move(file.FullName, Regex.Replace(file.FullName, "(.StoredProcedure)", ""));
  76. }
  77.  
  78. DirectoryInfo dicV = new DirectoryInfo(clArgument + "View\");
  79. FileInfo[] infosV = dicV.GetFiles();
  80. foreach (FileInfo file in infosV)
  81. {
  82. File.Move(file.FullName, Regex.Replace(file.FullName, "(.View)", ""));
  83. }
  84.  
  85. // ^^^ Deleting the filename-sufixes ^^^
  86.  
  87. }
  88. else
  89. {
  90. //Yet another thing to do
  91. }
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment