0

I have this function for validate a file copy : it an important function of backup so i have to be sure both file are exactly the same (not implemented security and atribut yet).

Here it is:

 public class fileCheck
        {
            public bool sourceExist { get; set; }
            public bool DestExist { get; set; }
            public bool bothSizeMatch { get; set; }
            public bool bothDateMatch { get; set; }
            public bool bothAclMatch { get; set; }


        }
        public fileCheck fileAlreadyExist(string source, string dest)
        {
            fileCheck f = new fileCheck();
            if (File.Exists(source))
            {
                f.sourceExist = true;

            }
            else
            {
                f.sourceExist = false;
            }
            if (File.Exists(dest))
            {
                f.DestExist = true;

            }
            else
            {
                f.DestExist = false;
            }

            if (f.sourceExist && f.DestExist)
            {

                FileInfo F1 = new FileInfo(source);
                FileInfo F2 = new FileInfo(dest);
                long len2 = F2.Length;
                if ( F1.LastWriteTime == F2.LastWriteTime)
                {
                    f.bothDateMatch = true;
                }
                else
                {
                    f.bothDateMatch = false;
                }


                if (F1.Length == len2 )
                {
                    f.bothSizeMatch = true;
                }
                else
                {
                    f.bothSizeMatch = false;
                }
            }
            else
            {
                f.bothDateMatch = false;
                f.bothSizeMatch = false;
            }

            return f;

        }

now the problem is with file.LastWriteTime ! this code will work like expected on 2 ntfs disk server to server. but when i back up on usb key both date are different. why the file binary would change? i heard fat disk add like 1-2 seconde to lastwritetime value.

and how i can implemente something safe for compare on any disk?

i know i can do something like this for remove second error but not enough precision

if ( F1.LastWriteTime.ToString("MM/dd/yyyy") == F2.LastWriteTime.ToString("MM/dd/yyyy"))

feel free to tell if the function can be better since its critique that all file on A move on B with a good delta system.

Zwan
  • 632
  • 2
  • 6
  • 23

0 Answers0