判断某个文件是否存在~

hymnfish 2004-09-23 11:10:41
给一个指定的目录 如c:\temp\
该temp下面有 .jpg .htm文件
命名为1234.jpg 1235.jpg ...
1234.htm 1235.htm ...

接受一个4位数 ,如何确定是否存在该数字的jpg htm文件?
...全文
132 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
KahnWinsock 2004-09-23
  • 打赏
  • 举报
回复
致作者:
使用file类,有一个方法是exists(fullpath),用于判断作为参数的文件是否存在。
定义一个字符串类型,用于表示文件的全路径。这样,就可以把你用的四位数字写到串里面,形成全路径。
然后就可以有下面的例子:
dim path as string
path="c:\temp\" & cstr(1234) & ".htm"
if file.exists(path)=true then msgbox("file exists",,"")

OK:)
hymnfish 2004-09-23
  • 打赏
  • 举报
回复
全对 给分~
GSXiaoXiao 2004-09-23
  • 打赏
  • 举报
回复
mark
qqdao 2004-09-23
  • 打赏
  • 举报
回复
faint全是星星们,偶就不回答了,各位大大们回答都很有水平
wangsaokui 2004-09-23
  • 打赏
  • 举报
回复
using System.IO;

public bool checkfile(string var)
{
string path1 = @"c:\temp\"+var+".jpg";
string path2 = @"c:\temp\"+var+".htm";

if (File.Exists(path1))
{
if (File.Exists(path2))
{
Console.WriteLine("have two file type");
return true;
}
else
{
Console.WriteLine("only have jpg");
return true;
}
}
else
{
if (File.Exists(path2))
{
Console.WriteLine("only have htm type");
return true;
}
else
{
Console.WriteLine("nothing");
return false;
}
}
}
wangsaokui 2004-09-23
  • 打赏
  • 举报
回复
public bool checkfile(string var);
string path1 = @"c:\temp\"+var+".jpg";
string path2 = @"c:\temp\"+var+".htm";

if (File.Exists(path1))
{
if (File.Exists(path2))
{
Console.WriteLine("have two file type");
}
else
{
Console.WriteLine("only have jpg");
}
}
else
{
if (File.Exists(path2))
{
Console.WriteLine("only have htm type");
}
else
{
Console.WriteLine("nothing");
}
}


brightheroes 2004-09-23
  • 打赏
  • 举报
回复
if(System.IO.File.Exists(@"C:\temp\" + 你的四位数 + ".jpg") &&
(System.IO.File.Exists(@"C:\temp\" + 你的四位数 + ".htm"))

{

}
jiezhi 2004-09-23
  • 打赏
  • 举报
回复
string path = @"c:\temp\"+yourFileNumber.ToString()+".htm";

if (File.Exists(path))
{
//
}
saucer 2004-09-23
  • 打赏
  • 举报
回复
int i = ..;

string s = i.ToString() + ".jpg";

if (System.IO.File.Exists(Server.MapPath(s))
{
//..
}

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧