如何检查图像文件是否存在与扩展名无关 [英] how to check the image file exist or not independent of extension
问题描述
i编写代码以检查图像是否存在于文件夹中而不使用单个扩展名,但我需要检查所有图像扩展我如何修改脚本
即我想检查是否,jpg,.jpeg,.png,.gif扩展名
var path =../mapimages/+ name +。png;
$。 ajax({
url:path,
类型:'HEAD',
错误:function(){
提醒(不存在);
},
成功:function(){
alert(文件在这里做点什么);
}
});
.ajax({
url:path,
类型:'HEAD',
错误:function(){
alert(不存在); < br $>
},
成功:功能(){
alert(文件存在在这里执行某些操作);
}
});
在C#中您可以通过传递文件夹名称和编程方式来检查图像名称或图像名称,如果文件夹已修复
string folderPath = Images;
string fileName = img1跨度>;
DirectoryInfo root = new DirectoryInfo(Server.MapPath( 〜/跨度> + FOLDERPATH));
FileInfo [] listfiles = root.GetFiles(fileName + 。*);
if (listfiles.Length > 0 )
{
// 文件存在
// 执行一些代码
}
else
{
// 文件不存在
// 做一些代码
}
Hi,
i written the code to check whether the image exist in a folder or not without using single extension,but i need to check the all images extensions how i can modify the script
i.e i want to check if for ,jpg,.jpeg,.png,.gif extension
var path = "../mapimages/" + name + ".png";
$.ajax({
url: path,
type: 'HEAD',
error: function () {
alert("does not exist");
},
success: function () {
alert("file exists do something here");
}
});
.ajax({
url: path,
type: 'HEAD',
error: function () {
alert("does not exist");
},
success: function () {
alert("file exists do something here");
}
});
In C# You can check programmatically by passing folder name and image name or just image name if folder is fixed
string folderPath = "Images"; string fileName = "img1"; DirectoryInfo root = new DirectoryInfo(Server.MapPath("~/"+folderPath)); FileInfo[] listfiles = root.GetFiles(fileName+".*"); if (listfiles.Length > 0) { //File exists //do some code } else { //File does not exist //Do some code }
这篇关于如何检查图像文件是否存在与扩展名无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!