Hi,
i have been looking into moving the newest file in a folder to another folder. i have used the following code. It works to a point. if there is 3 files in the folder it moves all 3 files. how would i kill it at just the 1.
[code]
public void Main()
{
// Uncomment to view status in messaage box while debugging
if (Equals("CurrentlyProcessing.arc", Dts.Variables["User::CurrentFile"].Value) == false)
{
//System.Windows.Forms.MessageBox.Show(Convert.ToString(Dts.Variables["User::CurrentFile"].Value));
Dts.Variables["User::FileName"].Value = "";
// string filename = (string)Dts.Variables["User::CurrentFile"].Value;
///=FileInfo fileinfo;
//fileinfo = new FileInfo(filename);
var directory = new DirectoryInfo(Dts.Variables["User::DataLoadFilePath"].Value.ToString());
FileInfo[] files = directory.GetFiles();
DateTime lastModified = DateTime.MinValue;
foreach (FileInfo file in files)
{
if (file.LastWriteTime > lastModified)
{
lastModified = file.LastWriteTime;
Dts.Variables["User::KeywordGLBAL"].Value = file.ToString();
}
}
MessageBox.Show(Dts.Variables["User::KeywordGLBAL"].Value.ToString());
//file's behavior
string GLBALFileBehavior = (string)Dts.Variables["User::GLBALFileBehavior"].Value;
//file's name keywords
string KeywordGLBAL = (string)Dts.Variables["User::KeywordGLBAL"].Value;
//if (filename.ToUpper().Contains(KeywordGLBAL.ToUpper()) && Equals("MOVE", GLBALFileBehavior.ToUpper()) == true
// && DateTime.Compare(fileinfo.CreationTime, (DateTime)Dts.Variables["User::LastCreateGLBAL"].Value) < 0)
{
Dts.Variables["User::FileName"].Value = Dts.Variables["User::CurrentFile"].Value;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
}
[\code]