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:
- public static class ReadingTxt
- {
- static Thread _ThreadVerification;
-
- static string PendingFiles =@"D:\Pendrive\PENDENTS";
- static string FileFilesImported = @"D:\Pendrive\IMPORTED";
-
- static string FolderLogLog = @"D:\Pendrive\LogImportProvider";
-
- public static void Read ()
- {
-
- _ThreadVerification = new Thread;
- _ThreadVerification.Start ();
- }
-
-
- private static void CheckTime ()
- {
- while (true)
- {
- if (DateTime.Now.Hour == 16)
- {
- InsertLog ("");
- InsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
-
- try
- {
- DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);
-
-
- foreach (FileInfo file in dirPending.GetFiles ())
- {
- if (file.Extension == ".cpv")
- {
- Process File (file.FullName, file.Name);
- }
- }
-
- }
- catch (Exception)
- {
- throw;
- }
- finally
- {
- InsertLog ("\ n FIM ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
- }
- }
-
- Thread.Sleep (3600000);
- }
- }
- }
Method to move the file:
- private static void MoveFile (string FileName)
- {
- try
- {
- FileFilesImported + = "\\" + FileName;
- FileFilespendents + = "\\" + FileName;
- File.Move (FolderFiles, FileFilesImported);
- }
- catch (Exception)
- {
- throw;
- }
-
- }
Method of inserting the log:
- private static void InsertLog (string row)
- {
-
- if (! Directory.Exists (LogFileLog))
- {
- Directory.CreateDirectory (LogFileLog);
- }
-
-
- string FullPath = LogFileLog + "\\ LogTexto.txt";
- if (! File.Exists (FullPath))
- {
- using (File.Create (FullPath));
- }
-
-
- using (StreamWriter file = new StreamWriter (FullPath, true))
- {
- file.WriteLine (line);
- file.Dispose ();
- }
- }
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.