I want to move from the folder named Main a file and it should go to Folder 1 every 15 seconds and from Main to Folder 2 every 60 seconds.
The problem is that folders 1 and 2 will conflict on 60 seconds tick. For Folder 1 it would be 4th time ticking and taking files from Folder Main and for Folder 2 it will be the first time trying to take files from Main.
Can you advise me on how to block this 4th tick in Folder 1 and allow Folder 2 to take files from folder Main or prioritize it?
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Timer timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 60000; // 60 second
timer1.Start();
Timer timer2 = new Timer();
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = 15000; // 15 second
timer2.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
// started code to move the files
string rootFolderPath = @"C:\Users\Msi\OneDrive\Рабочий стол\Main";
string destinationPath = @"C:\Users\Msi\OneDrive\Рабочий стол\Direction 1";
string filesToMove = @"*.*";
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToMove);
foreach (string file in fileList)
{
string filename = Path.GetFileName(file);
File.Move(file, destinationPath + "\\" + filename);
// place this code where you are actually moving the file
}
}
private void timer2_Tick(object sender, EventArgs e)
{
// started code to move the files
string rootFolderPath = @"C:\Users\Msi\OneDrive\Рабочий стол\Main";
string destinationPath = @"C:\Users\Msi\OneDrive\Рабочий стол\Direction 2";
string filesToMove = @"*.*";
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToMove);
foreach (string file in fileList)
{
string filename = Path.GetFileName(file);
File.Move(file, destinationPath + "\\" + filename);
// place this code where you are actually moving the file
}
}
}