R
rta_vix
Guest
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 ()
{
// creation of the verification thread and its execution
_ThreadVerification = new Thread;
_ThreadVerification.Start ();
}
// will check whether or not to execute the method every 1 hour
private static void CheckTime ()
{
while (true)
{
if (DateTime.Now.Hour == 16) // If it is 07:00 AM in the morning
{
InsertLog ("");
InsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
try
{
DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);
// list files in the current directory
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); // 3,600,000 milliseconds equals 1 hour (Standby)
}
}
}
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)
{
// Create Log Folder, if it does not exist
if (! Directory.Exists (LogFileLog))
{
Directory.CreateDirectory (LogFileLog);
}
// Create Log File, if it does not exist
string FullPath = LogFileLog + "\\ LogTexto.txt";
if (! File.Exists (FullPath))
{
using (File.Create (FullPath));
}
// Write to LOG file
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.
Continue reading...
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 ()
{
// creation of the verification thread and its execution
_ThreadVerification = new Thread;
_ThreadVerification.Start ();
}
// will check whether or not to execute the method every 1 hour
private static void CheckTime ()
{
while (true)
{
if (DateTime.Now.Hour == 16) // If it is 07:00 AM in the morning
{
InsertLog ("");
InsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());
try
{
DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);
// list files in the current directory
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); // 3,600,000 milliseconds equals 1 hour (Standby)
}
}
}
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)
{
// Create Log Folder, if it does not exist
if (! Directory.Exists (LogFileLog))
{
Directory.CreateDirectory (LogFileLog);
}
// Create Log File, if it does not exist
string FullPath = LogFileLog + "\\ LogTexto.txt";
if (! File.Exists (FullPath))
{
using (File.Create (FullPath));
}
// Write to LOG file
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.
Continue reading...