ディレクトリ内の前日のフォルダーに基づいて翌日のフォルダーを作成する SSIS パッケージがあります。SSDT から直接パッケージを実行するとフォルダーが生成されますが、パッケージを Sql サーバー統合カタログに展開して実行すると、成功メッセージが表示されますが、フォルダーは作成されません。
以下のスクリプト タスク コードを参照してください。
public void Main()
{
// TODO: Add your code here
string DataLocation = Dts.Variables["User::FolderLocation"].Value.ToString();
string[] Folders = Directory.GetDirectories(DataLocation);
List<String> listFolders = new List<String>();
List<String> listFoldersonly = new List<String>();
List<int> lens = new List<int>();
List<String> dates = new List<String>();
List<DateTime> dd = new List<DateTime>();
//get list of folders in the Directory
if (Folders.Length > 0)
{
for (int x = 0; x < Folders.Length; x++)
{
listFolders.Add(Folders[x].ToString());
lens.Add(Folders[x].Length);
}
}
//store list of folders in an array
string[] arrayFolders = listFolders.ToArray();
int[] arrayLens = lens.ToArray();
DateTime minDate = DateTime.MaxValue;
DateTime maxDate = DateTime.MinValue;
DateTime nextdate;
for (int i = 0; i < arrayFolders.Length; i++)
{
//subtring the date from the folderlocation string
dates.Add(arrayFolders[i].ToString().Substring(arrayLens[i] - 10));
dd.Add(DateTime.Parse(arrayFolders[i].ToString().Substring(arrayLens[i] - 10)));
//get the max and min date
if (dd[i].Date < minDate)
minDate = dd[i];
if (dd[i] > maxDate)
maxDate = dd[i];
}
nextdate = maxDate.AddDays(1);
string nxtdate = nextdate.ToString("yyyy-MM-dd");
String newpath = DataLocation + "\\" + nxtdate;
Dts.Variables["User::CopyFolder"].Value = newpath.ToString();
Dts.Variables["User::ReturnDate"].Value = nextdate.ToString();
Directory.CreateDirectory(newpath);
Dts.TaskResult = (int)ScriptResults.Success;
}