Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:55:30+00:00 2026-06-08T18:55:30+00:00

I’m having some trouble integrating two pieces of code. The first checks the size

  • 0

I’m having some trouble integrating two pieces of code. The first checks the size of a file and the next one loops trough a SQL database and looks for a matching name for a file. I basically want to check if it’s a new file or if the file has changed since I logged some of it’s data last time.

This gets the size of each file in the directory

 // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("C:\\Users");
        // Get a reference to each file in that directory.
        FileInfo[] fiArr = di.GetFiles();
        // Display the names and sizes of the files.
        MessageBox.Show("The directory {0} contains the following files:", di.Name);
        foreach (FileInfo f in fiArr)
            MessageBox.Show("The size of" + f.Name + " is " + f.Length + " bytes.");

This code loops untill it finds a mach or untill all entries has been looked trough.

  try
            {
                // LINQ query for all files containing the word '.txt'.
                var files = from file in
                                Directory.EnumerateFiles("C:\\Users")
                            where file.ToLower().Contains(".txt")
                            select file;

            foreach (var file in files)
            {
                //Get path to HH file
                filename = System.IO.Path.GetFileName(file);

                tempString = "";

                //Keep looking trough database utill database empty or HH found
                while (inc != numberOfSessions && (filename != tempString))
                { 

                    sessionRow = sessions.Tables["Sessions"].Rows[inc];
                    tempString = sessionRow.ItemArray.GetValue(1).ToString();

                    inc++;
                }

Lets say ItemAttay.GetValue(2) returns the saved size of a file. How can i most efficiently keep the while loop going if

inc != numberOfSessions && (filename != tempString) && (sessionRow.ItemArray.GetValue(2) == f.length)

Thanks for having a look!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:55:31+00:00Added an answer on June 8, 2026 at 6:55 pm
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Data;
    
    
    
        class Program
        {
            static void Main(string[] args)
            {
                var files1 = new List<string>(Directory.GetFiles(args[0],
                    "*.txt",
                    SearchOption.AllDirectories));
    
    
                List<FileData> ListFiles = new List<FileData>();
    
                for (int i = 0; i < files1.Count; i++)
                { 
    
    
                FileInfo file = new FileInfo(files1[i]);
                FileData _tmpfile = new FileData(file.Name.ToString(), file.Length, 
                    File.GetLastWriteTime(files1[1]).ToString("yyyy-MM-dd H:mm:ss"),
                    File.GetLastAccessTime(files1[1]).ToString("yyyy-MM-dd H:mm:ss"));
                ListFiles.Add(_tmpfile);
                }
    
                DataSet sessions = new DataSet();
                DataTable dt = sessions.Tables["Sessions"];
                for (int i = 0; i < ListFiles.Count; i++)
                {
                    //compares every file in folder to database
                    FileData _tmp = ListFiles[i];
                    for (int j = 0; j < dt.Rows.Count; j++)
                    {
                        if (_tmp.GSFileName == dt.Rows[i][0].ToString())
                        { 
                            //put some code here
                            break; 
                        }
    
                        if (_tmp.GSSize == long.Parse(dt.Rows[i][1].ToString()))
                        {
                            //put some code here
                            break;
                        }
    
                    }
    
    
                }
    
    
    
            }
        }
        public class FileData
        {
            string FileName = "";
    
            public string GSFileName
            {
                get { return FileName; }
                set { FileName = value; }
            }
            long Size = 0;
    
            public long GSSize
            {
                get { return Size; }
                set { Size = value; }
            }
            string DateOfModification = "";
    
            public string GSDateOfModification
            {
                get { return DateOfModification; }
                set { DateOfModification = value; }
            }
            string DateOfLastAccess = "";
    
            public string GSDateOfLastAccess
            {
                get { return DateOfLastAccess; }
                set { DateOfLastAccess = value; }
            }
    
            public FileData(string fn, long si, string dateofmod, string dateofacc)
            {
                FileName = fn;
                Size = si;
                DateOfModification = dateofmod;
                DateOfLastAccess = dateofacc;
    
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
I have a reasonable size flat file database of text documents mostly saved in
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.