The purpose of this example is to: 1 Learn how to traverse all files in a specified folder 2 how the console enters and outputs the data code:
Using system;using system.io;namespace tosql{class tosql{static void Main () {String path = System.Environment.CurrentDirectory; System.Console.WriteLine ("Enter the folder name to read"); string name = Console.ReadLine ();p ath + = "\" + name; Getallfile (path);} public static void Getallfile (string path) {DirectoryInfo di = new DirectoryInfo (path);D irectoryinfo[] dis = di. GetDirectories (); foreach (DirectoryInfo xdi in dis) {System.Console.WriteLine (xdi. Name); Getallfile (XDi. FullName);} fileinfo[] files = di. GetFiles (); String sql = ""; string picurl = ""; string id = ""; foreach (FileInfo file in files) {id = (file. Name). Replace ("S_", ""). Replace (". jpg", ""). Replace (". png", "");p Icurl = "/uploads/supplyer/" + file. Name;sql = "UPDATE ' supplyer ' SET picurl= '" + Picurl + "' WHERE id=" + ID + ";"; System.Console.WriteLine (SQL);}}}
C # reads all the files in the specified folder and generates SQL statements by rules!