Check if File exists in directory ignoring the extension

后端 未结 3 1880
死守一世寂寞
死守一世寂寞 2021-01-12 05:59

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

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 06:29

    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

提交回复
热议问题