检查文件是否存在于目录中忽略扩展 [英] Check if File exists in directory ignoring the extension

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

问题描述

我使用.NET 2.0和LINQ是毫无疑问的。我想检查文件的目录里面不存在的文件扩展名的知识

我只需要这样的逻辑进行。

使用字符串文件名提供了使用搜索模式,而忽略了文件的扩展名目录1,检查文件是否存在

2.注册该文件,如果它们存在,数据绑定提供下载链接。如果文件不存在,然后开始上传文件。

更新: Directory.GetFiles() DirectoryInfo.GetFiles()确实解决了部分地方在我检查文件是否存在。至于有关的FileInfo对象的表现,这些是唯一的解决办法,以我的数据绑定的要求,提供下载链接

解决方案

  DirectoryInfo的根=新的DirectoryInfo(your_directory_path);
的FileInfo [] listfiles = root.GetFiles(虚拟*。);
如果(listfiles.Length大于0)
{
  //文件存在
  的foreach(在listfiles FileInfo的文件)
        {
            //获取文件名和下载链接在这里
        }
}
其他
{
  //文件不存在
  //上传
}
 

希望这个作品

I am using .NET 2.0 and Linq is out of question. I would like to check if file exists inside a directory without knowledge of the file extension.

I just need this logic done.

1.Check File exists in Directory using String Filename provided using search pattern leaving out the extension of the File

2.Get the Files if they exists and Databind to provide Download links.If file does not exist then start uploading the File.

Update: Directory.GetFiles() and DirectoryInfo.GetFiles() indeed solves the part where in i check for File existence. As for the performance regarding FileInfo objects, these were only solution to my requirements of databinding to provide download links

解决方案

DirectoryInfo root = new DirectoryInfo("your_directory_path");
FileInfo[] listfiles = root.GetFiles("dummy.*");
if (listfiles.Length > 0)
{
  //File exists
  foreach (FileInfo file in listfiles)
        {
            //Get Filename and link download here
        }
}
else
{
  //File does not exist
  //Upload
}

Hope this works

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

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