本文介绍了如何检查文件中是否包含C#文件夹中的扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如何检查文件是否包含 文件夹 c#? 我有文件扩展名为FTS和FTS.SHA的文件夹。我需要检查FTS文件是否还包含.FTS.SHA文件。 我的意思是如果有x.FTS文件那么它也应该有x.FTS.SHA文件。 我可以获取如下文件。但是如何执行上述验证标准。 string [] fileList = Directory.GetFiles(COMMON。 FPPath,SearchFilePattern) .Select(f = > f.ToUpperInvariant()) / / 。其中(f => f.StartsWith(ec)|| f.StartsWith(es)) 。 ToArray(); 我尝试过: string [] fileList = Directory.GetFiles(COMMON.FPPath,SearchFilePattern) .Select(f = > f.ToUpperInvariant()) // 。其中(f => f.StartsWith(ec)|| f.StartsWith(es)) .ToArray(); 解决方案 if (Directory.GetFiles(dirPath, *。*)。长度== 0 ) { // 无匹配* .wma文件 } else { // 具有匹配的* .wma文件 } 您好,请参阅此代码, public void CheckFiles() { string FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ \\FileCheck; string [] FileArray = Directory.GetFiles(FolderPath); foreach ( string stringFile in FileArray) { FileInfo objFile = new FileInfo(stringFile); if (objFile.Extension == .FTS) { string SHAFileName = objFile.Name + 。SHA; int FTSSHAFilesCount = FileArray.Count(FTSSHAFile = > FTSSHAFile.Contains(SHAFileName)) ; if (FTSSHAFilesCount > 0 ) { Console.WriteLine( --------- -------找到匹配----------------); Console.WriteLine(objFile); Console.WriteLine(SHAFileName); Console.WriteLine( ----------------- --------------------------); } else { Console.WriteLine( ----------------匹配未找到----------------); Console.WriteLine(objFile); } } } } 这对我有用,我测试过桌面文件夹 FileCheck ,文件包括abc.FTS,abc.FTS.SHA,abd.FTS,abd.FTS.SHA,xyz.FTS。 How to check whether a file contains an extension in a folder in c#?I am having folder with file extension FTS and FTS.SHA. I need to check whether a FTS file contains .FTS.SHA file also.I mean if there x.FTS file then it should have x.FTS.SHA file too. I can fetch the files as below. But how to do the above validation criteria.string[] fileList = Directory.GetFiles(COMMON.FPPath, SearchFilePattern) .Select(f => f.ToUpperInvariant()) //.Where(f => f.StartsWith("ec") || f.StartsWith("es")) .ToArray();What I have tried:string[] fileList = Directory.GetFiles(COMMON.FPPath, SearchFilePattern) .Select(f => f.ToUpperInvariant()) //.Where(f => f.StartsWith("ec") || f.StartsWith("es")) .ToArray(); 解决方案 if (Directory.GetFiles(dirPath, "*.*").Length == 0){ //NO matching *.wma files}else{ //has matching *.wma files}Hi, Refer this code,public void CheckFiles(){ string FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\FileCheck"; string[] FileArray = Directory.GetFiles(FolderPath); foreach (string stringFile in FileArray) { FileInfo objFile = new FileInfo(stringFile); if (objFile.Extension == ".FTS") { string SHAFileName = objFile.Name + ".SHA"; int FTSSHAFilesCount = FileArray.Count(FTSSHAFile => FTSSHAFile.Contains(SHAFileName)); if (FTSSHAFilesCount > 0) { Console.WriteLine("----------------MATCH FOUND----------------"); Console.WriteLine(objFile); Console.WriteLine(SHAFileName); Console.WriteLine("-------------------------------------------"); } else { Console.WriteLine("----------------MATCH NOT FOUND----------------"); Console.WriteLine(objFile); } } }}It is working for me, I have tested with a desktop folder FileCheck with files like, abc.FTS, abc.FTS.SHA, abd.FTS, abd.FTS.SHA, xyz.FTS. 这篇关于如何检查文件中是否包含C#文件夹中的扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 14:11