Question compare image paths

MelodyS

Member
Joined
Nov 22, 2021
Messages
13
Programming Experience
1-3
So i'm trying to retrieve the image paths from the database as well as the same image path on file system,I need a way to compare both results to check if they are the same.
the paths are being retrieved on console application .
cronjob:
//File System
            string rootPath = @"D:\Images";

            string[] dirs = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories);
            foreach (string dir in dirs)
            {
                Console.WriteLine(dir);
            }

            //Sql Connection
            SqlConnection conn   = new SqlConnection(@"Data Source=DESKTOP-3PSF3SE;Initial Catalog=MediaCleaner_DB;Integrated Security=True");
            conn.Open();
            SqlDataAdapter sqlda = new SqlDataAdapter("Select ImageFileName from ImageDetails", conn);

            DataTable dtb1 = new DataTable();
            sqlda.Fill(dtb1);

            foreach (DataRow row in dtb1.Rows)
            {
                Console.WriteLine(row["ImageFileName"]);
            }
            Console.ReadLine();
 
That expected result because you passed in the entire array. Recall that C# doesn't unpack collections. You need:
C#:
var filePaths = Directory.GetFiles(@"D:\Images");
foreach(var path in filePaths)
    Console.WriteLine(path);
 
Back
Top Bottom