Hi Team,
Below is the code written on BUTTON_CLICK. After clicking on button files from SOURCE should copy to DESTINATION.
In SOURCE, files will be placed in multiple folders as shown below:
C:\\users\A\B\010\100 Files
C:\\users\A\B\011\100 Files
C:\\users\A\B\012\100 Files
But in DESTINATION, i need files to copy as per below folder structure as shown below:
D:\\users\Y\Z\001\25 Files
D:\\users\Y\Z\002\25 Files
D:\\users\Y\Z\003\25 Files
As per above example, it should create a sub-folder named 001 inside the destination path and folder limit should be only 25 files. After copying 25 files, it should copy the rest 25 into 002 folder.
I managed the code till filtering the specific file extensions in SOURCE path and copying to DESTINATION path.
Can you please help me folder threshold?
Below is the code written in button click:
private void button2_Click(object sender, EventArgs e)
{
string source = textBox1.Text;
string destination = textBox2.Text;
var thresholdvalue = textBox3.Text;
var extensions = new[] { ".tif", ".tiff", ".jpg", ".jpeg" };
var files = Directory.GetFiles(source, "*.*", SearchOption.AllDirectories);
foreach (var item in files)
{
if(extensions.Contains(Path.GetExtension(item)))
{
File.Copy(item, destination + Path.GetFileName(item));
}
}
var sizes = Directory.GetFiles(destination, "*.*", SearchOption.AllDirectories).Count();
MessageBox.Show("All " + sizes + " files are copied");
}
What I have tried:
i have tried adding sub-folders but failed to create threshold value dynamically.