Hi, I want to read source directory and copy each file to the destination by skipping after each file based on interval value i.e., if i set the value of interval 2, then it should skip two files everytime.
For Example: If there are 5 files in a directory, 1.txt, 2.txt, 3.txt, 4.txt and 5.txt and i have set the interval = 1, then my program should skip one text file after each file and copy 1, 3 and 5.txt to the destination.
I have a code which simply copies from source to destination.
static void Main(string[] args)
{
string fileName;
string destFile;
string sourcePath = @"E:\Source";
string targetPath = @"E:\Destination";
// To copy all the files in one directory to another directory.
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}