我有数以千计的项目文件夹,在每个文件夹中,我有另一个名为test的文件夹。此文件夹中只有一个pdf文件。当我选择顶部文件夹时,我希望在这些文件夹中获取pdfs并将它们复制到其他位置。如何选择这些pdfs?
在Project文件夹下还有其他pdfs,我只想在测试文件夹中使用pdfs。
我的文件夹名正在逐个增加(Project1,Project2,3,4,5,6,7.)
我的计划
↳-项目1
超临界↳试验
副业-↳项目-项目1.pdf
↳-项目2
↳/T1583-1993工业用↳检验
(↳)项目2.pdf
↳-项目3
↳/T1583-1993工业用↳检验
(↳)项目2.pdf
这张照片是我的。目前,它只列出选定文件夹中的所有pdfs。我不能过滤pdf文件。我使用FolderBrowserDialog来选择文件夹
发布于 2022-02-22 18:13:23
private string[] dirs;
private string[] files;
private System.IO.FileInfo file;
private void GetPDF(string path, ref List<string> listPDF)
{
try
{
dirs = System.IO.Directory.GetDirectories(path);
foreach (string item in dirs)
{
GetPDF(item, ref listPDF);
}
files = System.IO.Directory.GetFiles(path);
foreach (string item in files)
{
file = new System.IO.FileInfo(item);
if (file.DirectoryName.ToLower().EndsWith("test") && file.Extension.ToLower() == ".pdf")
{
listPDF.Add(file.FullName);
}
}
}
catch (Exception)
{
throw;
}
}
private void Function1()
{
try
{
System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
List<string> listPDF = new List<string>();
GetPDF(dialog.SelectedPath, ref listPDF);
listPDF.Sort();
foreach(string filePath in listPDF)
{
Console.WriteLine(filePath);
}
}
}
catch (Exception)
{
throw;
}
}
https://stackoverflow.com/questions/71217432
复制