gpt4 book ai didi

c# - 检查文件是否存在不知道扩展名

转载 作者:太空狗 更新时间:2023-10-29 20:54:36 24 4
gpt4 key购买 nike

有没有简单的方法来检查文件是否存在?我知道文件的名称,但不知道扩展名。

文件的名称将始终是他们在表中的用户 ID。

所以对我来说我可以是 1.*

.jpg、.jpeg、.gif 中的任何内容。 .png 等图像格式。

这容易吗,还是我应该将文件扩展名上传到数据库?

if (System.IO.File.Exists("~/ProfilePictures/" + userID " + ".*"))
{
}

最佳答案

使用Directory.GetFiles

类似于:

var files = Directory.GetFiles("~/ProfilePictures/",userID + ".*");
if (files.length > 0)
{
// at least one matching file exists
// file name is files[0]
}

关于c# - 检查文件是否存在不知道扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22641503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com