我尝试了在 this thread 上找到的内容但并没有完全按照我想要的方式工作...我有一个名为 photos
的文件夹,它可能
有图片或没有。 图片名称
是客户的入学资格
。我需要将 matriculation
作为 parameter
传递,并检查是否有带有 matriculation
名称的 picture
我作为参数
我试过这个:
public void VerifyPhoto(string matriculation)
{
string path = Txt_PhotosPath.Text;
var file = Directory.GetFiles(path, matriculation + ".jpg");
}
如何检查它是否找到了图片?我试着比较这个,file != null
但它不适用于 var
类型。任何提示? 调试
我看到它找到了图片,因为有一个 String[1]
但我不知道如何检查
它...
---更新--- 路径
:C:"\Users\admin\Desktop\photos"入学条件
:"607659.jpg"
有一个具有该名称的文件,但它一直返回 false
出了什么问题?
string path = Txt_PhotosPath.Text;
string filename = string.Format("{0}.jpg", matriculation);
if (Directory.Exists(path))
{
if (File.Exists(Path.Combine(path, filename)))
{
return true;
}
else
return false;
}
else
return false;
最佳答案
if (File.Exists(Path.Combine(path, matriculation + ".jpg"));
关于c# - 如何查看文件夹内的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14686376/