これまでご協力いただきありがとうございました。私は一般的にC#とコードに非常に慣れていません。答えが見つからないように見える質問があります。
あるフォルダーからその日の日付という名前の新しいフォルダーにファイルを移動する簡単なプログラムを作成しました。下記を参照してください:
private void button1_Click(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
string date = (now.ToString("D"));
string a = @"m:\\staff docs\\faxes\\";
string b = @a + date + "\\";
System.IO.Directory.CreateDirectory(b);
DirectoryInfo dir1 = new DirectoryInfo("c:\\blah");
DirectoryInfo dir2 = new DirectoryInfo("@b");
FileInfo[] DispatchFiles = dir1.GetFiles();
if (DispatchFiles.Length > 0)
{
foreach (FileInfo aFile in DispatchFiles)
{
string files = @b + aFile.Name;
int count = 0;
Find :
if (File.Exists(files))
{
files = files + "(" + count.ToString() + ").txt";
count++;
goto Find;
}
aFile.MoveTo(files);
}
}
{
MessageBox.Show("Your files have been moved!");
ユーザーにソースフォルダー変数と宛先フォルダー変数を定義してもらいたいのですが、ファイルブラウザーでフォルダーに移動するか、Console.ReadLine を使用しますが、プログラムを実行するたびにではなく、最初だけ. 後でパスを変更したい場合もパスを変更できれば理想的です。
どうもありがとう!
編集
私の解決策は、このブロックを呼び出すフォームのボタンでした:
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select source folder";
fbd.ShowDialog();
string Source = fbd.SelectedPath;
Properties.Settings.Default.source = Source;
Properties.Settings.Default.Save();
FolderBrowserDialog fbd2 = new FolderBrowserDialog();
fbd2.Description = "Select destination folder";
fbd2.ShowDialog();
string d1 = fbd2.SelectedPath;
string d2 = "\\";
string Destination = d1 + d2;
Properties.Settings.Default.destination = Destination;
Properties.Settings.Default.Save();
}