问题描述
[STAThread]
static void Main(string [] args)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
// fbd.Filter =txt文件(* .txt)| * .txt |所有文件(*。*)| *。*;
if(fbd.ShowDialog()== DialogResult.OK)
{
Console.WriteLine(Hello);
foreach(Directory.GetFiles中的var路径(fbd.SelectedPath))
{
Console.WriteLine(请选择文件夹) ;
Console.WriteLine(路径); //完整路径
Console.WriteLine(System.IO.Path.GetFileName(path)); //文件名
Console.WriteLine(路径+路径);
Console.ReadLine();
}
}
}
}
我尝试过:
我已经尝试过此代码来选择文件,但文件会自动被选中,因为它只允许选择文件夹而不是文件。
[STAThread]
static void Main(string[] args)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
// fbd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
if (fbd.ShowDialog() == DialogResult.OK)
{
Console.WriteLine("Hello");
foreach (var path in Directory.GetFiles(fbd.SelectedPath))
{
Console.WriteLine("Please select Folder");
Console.WriteLine(path); // full path
Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
Console.WriteLine("path"+ path);
Console.ReadLine();
}
}
}
}
What I have tried:
I've tried this code for selecting the file but the file is automatically getting selected, as in it allows only to choose the folder and not the file.
推荐答案
这篇关于如何在控制台应用程序中选择文件和目标目录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!