私がやりたいことを説明するためにここで何をグーグルで検索すればよいかわからないので、ここで試してみます。ファイルとディレクトリをそれぞれ参照するために、コードでOpenFileDialog
との両方を使用しています。FolderBrowserDialog
ダイアログが開くと、ユーザーはファイル/ディレクトリのツリーを実際に参照するオプションのみを取得します。ただし、多くのディレクトリとサブディレクトリを含むツリーでは、ユーザーは、移動先のフル パスを手動で暗黙的に書き込む (または貼り付ける) オプションも必要とします。
コードにどのように実装できますか?
ダイアログ ボックスを使用する 2 つの関数を次に示します。
FolderBrowserDialog の使用:
private void buttonAddDirectory_Click(object sender, EventArgs e)
{
this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
folderBrowserDialog.SelectedPath = "C:\\";
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderBrowserDialog.SelectedPath;
if (!searchForFiles(selectedPath))
{
MessageBox.Show("The directory: " + selectedPath + " doesn't contain sequences.", "Error!");
return;
}
testForm.enableNumOfProcesses();
createNewCommand(runBatchScript, selectedPath, true);
}
}
OpenFileDialog の使用:
private void buttonAddFile_Click(object sender, EventArgs e)
{
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.InitialDirectory = "C:\\";
openFileDialog.Filter = "PMD files (*" + sequenceExtenssion + ")|*" + sequenceExtenssion + "|All files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string selectedFile = openFileDialog.FileName;
if (Path.GetExtension(selectedFile).CompareTo(sequenceExtenssion) != 0)
{
MessageBox.Show("The file: " + selectedFile + " is not a sequence file.", "Error!");
return;
}
createNewCommand(batchRunExe, selectedFile, false);
}
}