Advertisement
sindrijo

SqlStatementMaker

May 6th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.IO;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             string path = "C:\\Users\\Sindri\\Dropbox\\G21\\Sprint 6\\Munchbilder"; // Hvor bildene ligger på din disk
  17.  
  18.             List<string> fileNames = new List<string>();
  19.             FileStream fs = new FileStream("SQLStatements.txt", FileMode.Create, FileAccess.Write);
  20.             StreamWriter sw = new StreamWriter(fs);
  21.  
  22.             foreach (string file in Directory.EnumerateFiles(path, "*.png"))
  23.             {
  24.                 int start = file.LastIndexOf('\\')+1;
  25.                 int end = (file.Length - start) - 4;
  26.                 string filename = file.Substring(start, end);
  27.  
  28.                 Console.WriteLine(toSQL(filename));
  29.                 sw.WriteLine(toSQL(filename));
  30.             }
  31.             sw.Flush();
  32.             sw.Close();
  33.  
  34.             Console.ReadKey(true);
  35.         }
  36.  
  37.         public static string toSQL(string input)
  38.         {
  39.             string retval = "";
  40.             string[] names = input.Split('-');
  41.  
  42.             if (names.Length > 1)
  43.             {
  44.                retval = "INSERT INTO paintings VALUES (NULL," + "'" + names[0] + "'" + ", " + "'" + names[1] + "'" + ",0);";
  45.             }
  46.  
  47.             return retval;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement