将数组中的文件名与目录文件名匹配 [英] Matching file names from an array with directory file names

查看:80
本文介绍了将数组中的文件名与目录文件名匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据库中的文件名与目录的文件名实际匹配.我已经将数据库中的文件名存储到一个数组中.该数组由根据特定条件选择的多个文件名组成.现在,我应该将这些文件名与目录中的文件名进行匹配.如果文件名匹配/存在,那么我将向用户显示文件以供下载.有帮助吗?......

Im trying to actually match the file names from a database with the filenames of a directory. I have stored the filenames from the database into an array. This array consist of multiple filenames selected upon a certain criteria. Now I''m supposed to match these filenames with the filenames from the directory. If the filename matches/exists then I''ll display the file to the user for downloading. Any help?......

推荐答案

这将是一种实现方法,将有无数其他方法.

This would be one way to do it, there would be countless of other ways.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
   class Program
   {
      static void Main(string[] args)
      {
         List<string> filenamesFromDatabase = new List<string>();
         List<string> filenamesFromDirectory = new List<string>();

         filenamesFromDatabase.Add("firstfile.txt");

         filenamesFromDirectory.Add("firstfile.txt");
         filenamesFromDirectory.Add("anotherfile.txt");

         foreach (string filename in filenamesFromDirectory)
         {
            if (filenamesFromDatabase.Any(s => filename.Contains(s)))
            {
               //Display the file to the user for downloading here
               Console.WriteLine(filename);
            }
         }

         Console.ReadLine();
      }
   }
}



输出:firstfile.txt



Output: firstfile.txt


这篇关于将数组中的文件名与目录文件名匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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