C#如何找到没有全名的文件夹? [英] C# how to find a folder without having the full name?

查看:110
本文介绍了C#如何找到没有全名的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要一些帮助。我需要找到每个新版本更改其名称的文件夹,但它始终具有相同的初始名称。在SCF的情况下,它总是更改为SCF1,SCF2,SCFNEW这样的名称如何找到只有初始名称不变的文件夹?



Hello everyone, I need some help. I need to find the folder that each new version changes its name, but it always has the same initial name. In the case of "SCF" But it always changes to names like "SCF1", "SCF2", SCFNEW "how do I find the folder having only the initial name that does not change?

<pre> void ScanOldVersion1()
            {
            try
                {
               
                string download = Environment.GetEnvironmentVariable("ProgramData") + @"\"+"SCF";
                MessageBox.Show(download);
                new List<string>(Directory.GetFiles(download)).ForEach(file =>
                {
                    if (file.IndexOf(".PDF", StringComparison.OrdinalIgnoreCase) >= 0)
                        PatchFile(file, file);
                    
                });
                }
            catch { }
                {

                }





我尝试过:





What I have tried:


需要类似的东西。



Need something like that.

<pre>void ScanOldVersion1()
            {
            try
                {
               
                string download = Environment.GetEnvironmentVariable("ProgramData") + @"\".Contains"SCF";
                MessageBox.Show(download);
                new List<string>(Directory.GetFiles(download)).ForEach(file =>
                {
                    if (file.IndexOf(".PDF", StringComparison.OrdinalIgnoreCase) >= 0)
                        PatchFile(file, file);
                    
                });
                }
            catch { }
                {

                }









我试试但没什么





I try it but nothing

void ScanOldVersion1()
           {
           try

               {
               string[] dirs = Directory.GetDirectories(@"C:\ProgramData", "SCF", SearchOption.AllDirectories);

               foreach (string dir in dirs)
                   {
                   new List<string>(Directory.GetFiles(dir)).ForEach(file =>
                   {
                       if (file.IndexOf(".PDF", StringComparison.OrdinalIgnoreCase) >= 0)
                           PatchFile(file, file);

                   });
                   }
               }



           catch { }
               {

               }
           }

推荐答案

使用此: Directory.GetDirectories方法(String,String,SearchOption)(System.IO) [ ^ ]

Use this: Directory.GetDirectories Method (String, String, SearchOption) (System.IO)[^]
string[] dirs = Directory.GetDirectories(strPathToRootOfSearch, "SCF*", SearchOption.AllDirectories);


这篇关于C#如何找到没有全名的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆