This project is read-only.
1
Vote

impFileSynch.dll is not copying the files correctly

description

Sorry, there is a backslash missing when the new file name is being put together, so the files endup in the wrong folder and with the wrong filename.
 
The source code is here and the updated dll is attached.
 
 
    private void ProcessFile(FileInfo sourcefile)
    {
 
        if (FileIsIncluded(sourcefile) && FileIsNotExcluded(sourcefile))
        {

            //now check how old the file is:
            TimeSpan span = DateTime.Now - sourcefile.LastWriteTime;
            double DaysOld = span.TotalHours;
            string thisfiletargetpath = "";
            Boolean passedfilecompare;
 
            int isourcelength = _processFolder.Length;
            if (sourcefile.DirectoryName.Length <= isourcelength)
            {
                thisfiletargetpath = _targetFolder;
            }
            else
            {
                thisfiletargetpath = _targetFolder + sourcefile.DirectoryName.Substring(isourcelength);
            }
 
            if (thisfiletargetpath.Substring(thisfiletargetpath.Length - 1, 1) != "\\")
            {
                thisfiletargetpath = thisfiletargetpath + "\\";
            }
 
            string newfilename = thisfiletargetpath + sourcefile.Name;
 
            passedfilecompare = false;
            if (_CompareEachFile == true)
            {

                //check if the file exists.  
                if (File.Exists(newfilename))
                {
                    System.IO.FileInfo fTarget;
                    fTarget = new System.IO.FileInfo(newfilename);
                    if ((fTarget.LastWriteTime < sourcefile.LastWriteTime) || (fTarget.Length < sourcefile.Length))
                    {
                        //the file changed since last time, copy it
                        passedfilecompare = true;
                    }
                    else
                    {
                        //the file has not changed, dont copy it.
                        passedfilecompare = false;
                    }
                }
                else
                {
                    //file doesn't exist
                    passedfilecompare = true;
                }
            }
 
            if (_IsFirstRun == true || (_CompareEachFile == false || _CompareEachFile ==true && passedfilecompare == true) && (_UseHourSystem == false || (_UseHourSystem == true && DaysOld >= _NumHoursBack)))
            {
                    //compare the file if applicable.
 
                    CopyMoveTheFile(sourcefile, thisfiletargetpath, newfilename,DaysOld);

            }
        }
    }

file attachments

comments