Robson Amaral

Robson Amaral

  • NA
  • 132
  • 17.3k

Problem to read the next file

Aug 14 2018 6:02 AM

Guys, good afternoon! I am having trouble reading the files in a directory, it presents an error as if it were going the wrong way, but I do not see this fault, could someone guide me?

Here is where I check the file extension and inform the path:
  1. public static class ReadingTxt  
  2.     {  
  3.         static Thread _ThreadVerification;  
  4.   
  5.         static string PendingFiles =@"D:\Pendrive\PENDENTS";  
  6.         static string FileFilesImported = @"D:\Pendrive\IMPORTED";  
  7.   
  8.         static string FolderLogLog = @"D:\Pendrive\LogImportProvider";  
  9.   
  10.         public static void Read ()  
  11.         {  
  12.             // creation of the verification thread and its execution  
  13.             _ThreadVerification = new Thread;  
  14.             _ThreadVerification.Start ();  
  15.         }  
  16.   
  17.         // will check whether or not to execute the method every 1 hour  
  18.         private static void CheckTime ()  
  19.         {  
  20.             while (true)  
  21.             {  
  22.                 if (DateTime.Now.Hour == 16) // If it is 07:00 AM in the morning  
  23.                 {  
  24.                     InsertLog ("");  
  25.                     InsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());  
  26.   
  27.          try  
  28.                     {  
  29.                         DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);  
  30.   
  31.                         // list files in the current directory  
  32.                         foreach (FileInfo file in dirPending.GetFiles ())  
  33.                         {  
  34.                             if (file.Extension == ".cpv")  
  35.                             {  
  36.                                 Process File (file.FullName, file.Name);  
  37.                             }  
  38.                         }  
  39.   
  40.                     }  
  41.                     catch (Exception)  
  42.                     {  
  43.                         throw;  
  44.                     }  
  45.                     finally  
  46.                     {  
  47.                         InsertLog ("\ n FIM ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());  
  48.                     }  
  49.                 }  
  50.   
  51.                 Thread.Sleep (3600000); // 3,600,000 milliseconds equals 1 hour (Standby)  
  52.             }  
  53.         }  
  54. }  
Method to move the file:
  1. private static void MoveFile (string FileName)  
  2.         {  
  3.             try  
  4.             {  
  5.                 FileFilesImported + = "\\" + FileName;  
  6.                 FileFilespendents + = "\\" + FileName;  
  7.                 File.Move (FolderFiles, FileFilesImported);  
  8.             }  
  9.             catch (Exception)  
  10.             {  
  11.                 throw;  
  12.             }  
  13.   
  14.         }  
Method of inserting the log:
  1. private static void InsertLog (string row)  
  2.         {  
  3.             // Create Log Folder, if it does not exist  
  4.             if (! Directory.Exists (LogFileLog))  
  5.             {  
  6.                 Directory.CreateDirectory (LogFileLog);  
  7.             }  
  8.   
  9.             // Create Log File, if it does not exist  
  10.             string FullPath = LogFileLog + "\\ LogTexto.txt";  
  11.             if (! File.Exists (FullPath))  
  12.             {  
  13.                 using (File.Create (FullPath));  
  14.             }  
  15.   
  16.             // Write to LOG file  
  17.             using (StreamWriter file = new StreamWriter (FullPath, true))  
  18.             {  
  19.                 file.WriteLine (line);  
  20.                 file.Dispose ();  
  21.             }  
  22.         } 
Error: System.IO.FileNotFoundException: 'Could not find the file' D:\Pendrive\PENDENTES\CGc0001.cpv\CGc0360.cpv '.' This happens every time I read the next file.

Answers (6)