检查文件是否在目录中 [英] check if Files in directory

查看:102
本文介绍了检查文件是否在目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查给定数组文件名是否在本地目录中.在其他情况下,需要检查多个苍蝇名是否在目录中.....任何示例代码都会有很大帮助. br/>
谢谢

how to check if the give array file names exist in the local directory..In others multiple flies name needs to be checked if they exist in the directory.....Any sample codes would be of great help..

Thanks

while (myReader.Read())
            {
                string  i = myReader["Ref_Link"].ToString();
                test.Add(i);
                String[] filenames = (String[])test.ToArray(typeof(string));
}


String[]文件名包含文件名列表.


This String[] filenames contains the list of file names.

推荐答案

请使用System.IO.File.Exist:
http://msdn.microsoft.com/en-us/library/system. io.file.exists.aspx [ ^ ].

(请参阅我对问题的评论.您可以将每个文件名传递给此方法,或者将其与所讨论目录的完整路径名结合使用.)

—SA
Please use System.IO.File.Exist:
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx[^].

(Please see my comment to the question. You either pass each file name to this method, or combine it with the full path name of the directory in question.)

—SA


以下是提供解决方案的几个链接-

http://codingcluster.blogspot.in/2011/10/check- if-file-exists-using-c.html [ ^ ]
http://www.dotnetperls.com/file-exists [ [
Here are a couple of links that provide solutions -

http://codingcluster.blogspot.in/2011/10/check-if-file-exists-using-c.html[^]
http://www.dotnetperls.com/file-exists[^]


You can in addition, try exploring FileInfo.Exists()[^] as well.


这里是一个非常简短的示例:
Here is a very short sample:
private void button1_Click(object sender, EventArgs e)
{
   string[] filenames = new string[4];
   filenames[0] = "test.txt";
   filenames[1] = "test.txt";
   filenames[2] = "test2.txt";
   filenames[3] = "test3.txt";
   string strPath = @"C:\Temp\";
   foreach(string str in filenames)
   {
      if (!File.Exists(strPath + str))
         MessageBox.Show("File: " + str + " does not exist in folder: " + strPath);
   }
}


这篇关于检查文件是否在目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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