私は1つの私的な空白から情報を取り込み、それを別のものに入れたいと思います。それは私がコードにしたいもので動作しません。ここでは、dlg2.selectedPathが動作していないコードがあります。このボタンは、必要な場所のprivate voidから認識されます。私は1つの私的な空きから情報を取って別のものに入れます
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg2 = new FolderBrowserDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
//do whatever with dlg.SelectedPath
{
backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
DirectoryInfo source = new DirectoryInfo(dlg.SelectedPath);
DirectoryInfo target = new DirectoryInfo(dlg2.SelectedPath);
DirectoryInfo dir = new DirectoryInfo(dlg.SelectedPath);
FileInfo[] fis = dir.GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo fi in fis)
{
if (fi.LastWriteTime.Date == DateTime.Today.Date)
{
File.Copy(fi.FullName, target.FullName + "\\" + fi.Name, true);
}
}
}
助けてください。
:あなたの
DoWork
ハンドラでは、DoWorkEventArgs
インスタンスから値を取得することができます。関連:http://stackoverflow.com/questions/4899281/c-backgroundworker-wont-work-with-the-code-i-want-it-to-do –これらは、コードIの同じ部分に関する2つの異なるクエリです私が持っていたそれぞれの問題を解決するために、両方から情報を得ました。 – bobthemac