Esempio n. 1
0
        /*
         * Go through the root folder and find all .docx files
         */
        public void InitialiseFiles(string sDir)
        {
            // Try to read through every directory and files nested inside the root
            try
            {
                string[] directoriesExists = Directory.GetDirectories(sDir);
                if (directoriesExists.Length > 0)
                {
                    foreach (string file in Directory.GetFiles(sDir))
                    {
                        TemppFileName       = Path.GetFileNameWithoutExtension(file);
                        TempFileNameWithExt = Path.GetFileName(file);
                        if (TemppFileName != "logfile" && TemppFileName.Substring(0, 2) != "~$")
                        {
                            if (TempFileNameWithExt.Contains(".docx"))
                            {
                                GetFileDirectories(file);
                            }
                        }
                    }
                    multiDir(sDir);
                }
                else
                {
                    // For each directory in root
                    foreach (string files in Directory.GetFiles(sDir))
                    {
                        TemppFileName       = Path.GetFileNameWithoutExtension(files);
                        TempFileNameWithExt = Path.GetFileName(files);
                        if (TemppFileName != "logfile" && TemppFileName.Substring(0, 2) != "~$")
                        {
                            if (TempFileNameWithExt.Contains(".docx"))
                            {
                                GetFileDirectories(files);
                            }
                        }
                    }
                }
            }

            // Error catching
            catch (Exception ex)
            {
                throw new Exception("Failed while searching for documents: " + ex.Message);
            }
        }
Esempio n. 2
0
 /*
  * Goes through each directory in the root path
  * Return all the document files that are not logfile and temporary edit word doc (~$)
  */
 public void multiDir(string strDir)
 {
     // For each directory in root
     foreach (string currDirectory in Directory.GetDirectories(strDir))
     {
         // For each files of that specific directory
         foreach (string currFile in Directory.GetFiles(currDirectory))
         {
             TemppFileName       = Path.GetFileNameWithoutExtension(currFile);
             TempFileNameWithExt = Path.GetFileName(currFile);
             if (TemppFileName != "logfile" && TemppFileName.Substring(0, 2) != "~$")
             {
                 if (TempFileNameWithExt.Contains(".docx"))
                 {
                     GetFileDirectories(currFile);
                 }
             }
         }
         multiDir(currDirectory);
     }
 }
Esempio n. 3
0
        /*
         * Main function
         * Goes through searched directory
         * replaces the content through "ReadDcox"
         * unless if the file is logfile or deselected
         */
        public void GetDocx(string sDir)
        {
            // Try to read through every directory and files nested inside the root
            try
            {
                string[] directoriesExists = Directory.GetDirectories(sDir);
                if (directoriesExists.Length > 0)
                {
                    foreach (string file in Directory.GetFiles(sDir))
                    {
                        TemppFileName = Path.GetFileNameWithoutExtension(file);
                        if (TemppFileName != "logfile" && TemppFileName.Substring(0, 2) != "~$")
                        {
                            ReadDocx(file);
                        }
                    }
                    SearchSubFolders(sDir);
                }

                else
                {
                    // For each directory in root
                    foreach (string files in Directory.GetFiles(sDir))
                    {
                        TemppFileName = Path.GetFileNameWithoutExtension(files);
                        if (TemppFileName != "logfile" && TemppFileName.Substring(0, 2) != "~$")
                        {
                            ReadDocx(files);
                        }
                    }
                }
            }

            // Error catching
            catch (Exception ex)
            {
                throw new Exception("Failed to update the documents: " + ex.Message);
            }
        }