L
lemming3k
Guest
Hi,
I'm currently trying to create new directories and copy files as part of a SSIS package, however the file copy doesn't complete. The folder creation works fine and the whole task completes successfully but the copy does not take place.
I'm writing this all as a script task because I also have to complete both the above tasks and to replace character strings. I've had issues with the foreach loop container bug deleting code so would like to avoid using these control flow items.
The code could probably do with refining as well as I'm repeating variables, so I wondered if anyone had any advice on where I'm going wrong and how to streamline?
public void Main()
{
{
var Today = DateTime.Today;
string pathyear = Today.ToString ("yyyy");
string pathmonth = Today.ToString ("MMMM");
string pathdate = Today.ToString ("dd");
string folder = Path.Combine(@"C:\Archive\", Path.Combine (pathyear, Path.Combine (pathmonth, pathdate)));
Directory.CreateDirectory(folder);
}
var Today2 = DateTime.Today;
string pathyear2 = Today2.ToString ("yyyy");
string pathmonth2 = Today2.ToString ("MMMM");
string pathdate2 = Today2.ToString ("dd");
string fileName = string.Empty;
string destFile = string.Empty;
string sourcePath = @"C:\Files\";
string targetPath = Path.Combine(@"C:\Archive\", Path.Combine (pathyear, Path.Combine (pathmonth, pathdate)));
if (System.IO.Directory.Exists(sourcePath))
{
string wildcard = "*.txt";
string[] files = System.IO.Directory.GetFiles(sourcePath, wildcard);
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine (targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
}
Continue reading...
I'm currently trying to create new directories and copy files as part of a SSIS package, however the file copy doesn't complete. The folder creation works fine and the whole task completes successfully but the copy does not take place.
I'm writing this all as a script task because I also have to complete both the above tasks and to replace character strings. I've had issues with the foreach loop container bug deleting code so would like to avoid using these control flow items.
The code could probably do with refining as well as I'm repeating variables, so I wondered if anyone had any advice on where I'm going wrong and how to streamline?
public void Main()
{
{
var Today = DateTime.Today;
string pathyear = Today.ToString ("yyyy");
string pathmonth = Today.ToString ("MMMM");
string pathdate = Today.ToString ("dd");
string folder = Path.Combine(@"C:\Archive\", Path.Combine (pathyear, Path.Combine (pathmonth, pathdate)));
Directory.CreateDirectory(folder);
}
var Today2 = DateTime.Today;
string pathyear2 = Today2.ToString ("yyyy");
string pathmonth2 = Today2.ToString ("MMMM");
string pathdate2 = Today2.ToString ("dd");
string fileName = string.Empty;
string destFile = string.Empty;
string sourcePath = @"C:\Files\";
string targetPath = Path.Combine(@"C:\Archive\", Path.Combine (pathyear, Path.Combine (pathmonth, pathdate)));
if (System.IO.Directory.Exists(sourcePath))
{
string wildcard = "*.txt";
string[] files = System.IO.Directory.GetFiles(sourcePath, wildcard);
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine (targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
}
}
}
Continue reading...