Hi,
You can use below code.
Code
public void CopyPreviousDayFile()
{
string destPath = "D:\\Users\\" + DateTime.Now.AddDays(-1).ToShortDateString().Replace("/", "-");
string sourcePath = "D:\\Users\\Shashikant\\test";
DirectoryInfo info = new DirectoryInfo(sourcePath);
var files = info.GetFiles();
foreach (FileInfo file in files)
{
if (file.CreationTime.ToShortDateString().Equals(DateTime.Now.AddDays(-1).ToShortDateString()))
{
using (FileStream stream = file.OpenRead())
{
bool exists = System.IO.Directory.Exists(destPath);
if (!exists)
{
System.IO.Directory.CreateDirectory(destPath);
}
bool existFile = System.IO.File.Exists(Path.Combine(destPath, file.Name));
if (!existFile)
{
string temppath = Path.Combine(destPath, file.Name);
File.Create(temppath);
file.CopyTo(temppath);
}
}
}
}
}